X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fconftest.py;h=3ef7fe1474c091fe4170ddccbb9b14cfdb45a28c;hb=b3a5befeb0d5d9e348b1ba7b29f412b15544a0ec;hp=98680678aff8c1bfa25872f8db82f5c673b632c9;hpb=84db7f8f65cd0ec77f09cfde365599df9890ce6c;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/conftest.py b/ice_validator/tests/conftest.py index 9868067..3ef7fe1 100644 --- a/ice_validator/tests/conftest.py +++ b/ice_validator/tests/conftest.py @@ -360,31 +360,27 @@ def pytest_collection_modifyitems(session, config, items): config.traceability_items = list(items) # save all items for traceability if not config.option.self_test: for item in items: - # checking if test belongs to a category - if hasattr(item.function, "categories"): - if config.option.test_categories: - test_categories = getattr(item.function, "categories") - passed_categories = config.option.test_categories - if not all( - category in passed_categories for category in test_categories - ): - item.add_marker( - pytest.mark.skip( - reason=( - "Test categories do not match " - "all the passed categories" - ) - ) + passed_categories = set(config.option.test_categories or []) + all_of_categories = getattr(item.function, "all_categories", set()) + any_of_categories = getattr(item.function, "any_categories", set()) + if all_of_categories and not all_of_categories.issubset(passed_categories): + item.add_marker( + pytest.mark.skip( + reason=( + "Test categories do not match " "all the passed categories" ) - else: - item.add_marker( - pytest.mark.skip( - reason=( - "Test belongs to a category but " - "no categories were passed" - ) + ) + ) + if any_of_categories and not passed_categories.intersection( + any_of_categories + ): + item.add_marker( + pytest.mark.skip( + reason=( + "Test categories do not match " "any the passed categories" ) ) + ) items.sort( key=lambda x: (0, x.name) @@ -833,7 +829,7 @@ def pytest_addoption(parser): "--env-directory", dest="env_dir", action="store", - help="optional directory of .env files for preload generation" + help="optional directory of .env files for preload generation", ) parser.addoption( @@ -843,7 +839,7 @@ def pytest_addoption(parser): help=( "Preload format to create (multiple allowed). If not provided " "then all available formats will be created: {}" - ).format(", ".join(get_generator_plugin_names())) + ).format(", ".join(get_generator_plugin_names())), )