X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fhelpers.py;h=37fd01f0dc9bab88585296560b4fe3e0255879b9;hb=06511c3ae3ed91250586d4b1c14130d83eaa64c8;hp=9cde1faf11ff4b149b2dec2e4a9aca3829c88a9c;hpb=cc21b8b08b6dbcec577bfb26ff397ac899da8002;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py old mode 100644 new mode 100755 index 9cde1fa..37fd01f --- a/ice_validator/tests/helpers.py +++ b/ice_validator/tests/helpers.py @@ -39,6 +39,7 @@ # import yaml +from boltons import funcutils def check_basename_ending(template_type, basename): @@ -54,10 +55,11 @@ def check_basename_ending(template_type, basename): return not basename.endswith('_volume') -def get_parsed_yml_for_yaml_files(yaml_files, sections=[]): +def get_parsed_yml_for_yaml_files(yaml_files, sections=None): ''' get the parsed yaml for a list of yaml files ''' + sections = [] if sections is None else sections parsed_yml_list = [] for yaml_file in yaml_files: yml = '' @@ -66,8 +68,8 @@ def get_parsed_yml_for_yaml_files(yaml_files, sections=[]): with open(yaml_file) as fh: yml = yaml.load(fh) except Exception as e: - print(e) - + print('Error in %s: %s' % (yaml_file, e)) + continue if yml: if sections: for k in yml.keys(): @@ -76,3 +78,27 @@ def get_parsed_yml_for_yaml_files(yaml_files, sections=[]): parsed_yml_list.append(yml) return parsed_yml_list + + +def validates(*requirement_ids): + """Decorator that tags the test function with one or more requirement IDs. + + Example: + >>> @validates('R-12345', 'R-12346') + ... def test_something(): + ... pass + >>> assert test_something.requirement_ids == ['R-12345', 'R-12346'] + """ + def decorator(func): + # NOTE: We use a utility here to ensure that function signatures are + # maintained because pytest inspects function signatures to inject + # fixtures. I experimented with a few options, but this is the only + # library that worked. Other libraries dynamically generated a + # function at run-time, and then lost the requirement_ids attribute + @funcutils.wraps(func) + def wrapper(*args, **kw): + return func(*args, **kw) + wrapper.requirement_ids = requirement_ids + return wrapper + decorator.requirement_ids = requirement_ids + return decorator