aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLovett, Trevor <trevor.lovett@att.com>2019-10-16 11:26:16 -0500
committerTrevor Lovett <trevor.lovett@att.com>2019-10-16 16:59:05 +0000
commit48d35093a120d5a8c02a28c4a72f4f7d69b664f4 (patch)
tree2cd1476affa455dcb00d0ec6bbebf59f0e600c3e
parent842888dc28ebccab45e627669f7ee23f04920dc7 (diff)
[VVP] Support any_of in categories decorator
If specified, then the test will be selected if any of the passed categories from the command line are in the tests categories. This is different than the default behavior where all categories must match Change-Id: Iee08556d6c07eac2663ff2ff2e89bcd7a18cd392 Issue-ID: VVP-330 Signed-off-by: Lovett, Trevor <trevor.lovett@att.com>
-rw-r--r--ice_validator/tests/conftest.py44
-rw-r--r--ice_validator/tests/helpers.py11
2 files changed, 30 insertions, 25 deletions
diff --git a/ice_validator/tests/conftest.py b/ice_validator/tests/conftest.py
index ecaf662..2a1cc55 100644
--- a/ice_validator/tests/conftest.py
+++ b/ice_validator/tests/conftest.py
@@ -360,31 +360,31 @@ 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"
- )
- )
+ all_of_categories = getattr(item.function, "all_categories", set())
+ any_of_categories = getattr(item.function, "any_categories", set())
+ if any_of_categories and all_of_categories:
+ raise RuntimeError(
+ "categories can not use 'any_of' with other categories"
+ )
+ passed_categories = set(config.option.test_categories or [])
+ 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"
- )
+ )
+ )
+ elif 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)
diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py
index 764be11..424dde1 100644
--- a/ice_validator/tests/helpers.py
+++ b/ice_validator/tests/helpers.py
@@ -124,16 +124,21 @@ def validates(*requirement_ids):
return decorator
-def categories(*categories):
+def categories(*all_of, any_of=None):
+ any_of = set(any_of) if any_of else set()
+ all_of = set(all_of) if all_of else set()
+
def decorator(func):
@funcutils.wraps(func)
def wrapper(*args, **kw):
return func(*args, **kw)
- wrapper.categories = categories
+ wrapper.all_categories = all_of
+ wrapper.any_categories = any_of
return wrapper
- decorator.categories = categories
+ decorator.all_categories = all_of
+ decorator.any_categories = any_of
return decorator