From 7d07564749b5704ebd45f7157b56ffcb37d689de Mon Sep 17 00:00:00 2001 From: Ruodi Lu Date: Fri, 26 Sep 2025 07:28:03 +0000 Subject: [PATCH] add test-model-suites in integration conftest.py Signed-off-by: Ruodi Lu --- tests/integration/defs/conftest.py | 62 ++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tests/integration/defs/conftest.py b/tests/integration/defs/conftest.py index 13bca1aa0b78..90eecd7bf7b6 100644 --- a/tests/integration/defs/conftest.py +++ b/tests/integration/defs/conftest.py @@ -2059,6 +2059,14 @@ def pytest_addoption(parser): action="append", default=[], ) + parser.addoption( + "--test-model-suites", + action="store", + default=None, + help= + "Specify test model suites separated by semicolons or spaces. Each suite can contain special characters. " + "Example: --test-model-suites=suite1;suite2;suite3 or --test-model-suites=suite1 suite2 suite3", + ) @pytest.hookimpl(trylast=True) @@ -2105,6 +2113,7 @@ def pytest_collection_modifyitems(session, config, items): waives_file = config.getoption("--waives-file") test_prefix = config.getoption("--test-prefix") perf_test = config.getoption("--perf") + test_model_suites = config.getoption("--test-model-suites") if perf_test: global ALL_PYTEST_ITEMS @@ -2135,6 +2144,10 @@ def pytest_collection_modifyitems(session, config, items): if regexp is not None: deselect_by_regex(regexp, items, test_prefix, config) + if test_model_suites: + deselect_by_test_model_suites(test_model_suites, items, test_prefix, + config) + if waives_file: apply_waives(waives_file, items, config) @@ -2154,6 +2167,55 @@ def pytest_configure(config): tqdm.tqdm.monitor_interval = 0 +def deselect_by_test_model_suites(test_model_suites, items, test_prefix, + config): + """Filter tests based on the test model suites specified. + If a test matches any of the test model suite names, it is considered selected. + + Args: + test_model_suites: String containing test model suite names separated by semicolons + items: List of pytest items to filter + test_prefix: Test prefix if any + config: Pytest config object + """ + if not test_model_suites: + return + + # Split by semicolon or space and strip whitespace + suite_names = [ + suite.strip() for suite in test_model_suites.replace(';', ' ').split() + if suite.strip() + ] + + if not suite_names: + return + + selected = [] + deselected = [] + + for item in items: + # Get the test name without prefix for comparison + test_name = item.nodeid + if test_prefix and test_name.startswith(f"{test_prefix}/"): + test_name = test_name[len(f"{test_prefix}/"):] + + # Check if any suite name matches the test name + found = False + for suite_name in suite_names: + if suite_name in test_name or test_name.endswith(suite_name): + found = True + break + + if found: + selected.append(item) + else: + deselected.append(item) + + if deselected: + config.hook.pytest_deselected(items=deselected) + items[:] = selected + + def deselect_by_regex(regexp, items, test_prefix, config): """Filter out tests based on the patterns specified in the given list of regular expressions. If a test matches *any* of the expressions in the list it is considered selected."""