[VVP] Support any_of in categories decorator
[vvp/validation-scripts.git] / ice_validator / tests / conftest.py
index f4b3857..2a1cc55 100644 (file)
@@ -44,7 +44,8 @@ import os
 import re
 import time
 
-from preload import create_preloads
+from preload.model import create_preloads
+from config import get_generator_plugin_names
 from tests.helpers import get_output_dir
 
 try:
@@ -359,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)
@@ -828,6 +829,23 @@ def pytest_addoption(parser):
         help="optional category of test to execute",
     )
 
+    parser.addoption(
+        "--env-directory",
+        dest="env_dir",
+        action="store",
+        help="optional directory of .env files for preload generation",
+    )
+
+    parser.addoption(
+        "--preload-format",
+        dest="preload_formats",
+        action="append",
+        help=(
+            "Preload format to create (multiple allowed). If not provided "
+            "then all available formats will be created: {}"
+        ).format(", ".join(get_generator_plugin_names())),
+    )
+
 
 def pytest_configure(config):
     """
@@ -1044,12 +1062,11 @@ def generate_rst_table(output_dir, data):
     rst_path = os.path.join(output_dir, "rst.csv")
     with open(rst_path, "w", newline="") as f:
         out = csv.writer(f)
-        out.writerow(("Requirement ID", "Requirement", "Test Module", "Test Name"))
+        out.writerow(("Requirement ID", "Test Module", "Test Name"))
         for req_id, metadata in data.items():
             out.writerow(
                 (
                     metadata["full_title"],
-                    metadata["description"],
                     metadata["test_case"],
                     metadata["validated_by"],
                 )