X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fhelpers.py;h=82d0201086eaa47374dd9d4710644bac60f63087;hb=7e08a8738145295de2937f00231e4ec13db1e9b0;hp=9cde1faf11ff4b149b2dec2e4a9aca3829c88a9c;hpb=cc21b8b08b6dbcec577bfb26ff397ac899da8002;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py index 9cde1fa..82d0201 100644 --- 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): @@ -76,3 +77,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