Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions tests/integration/defs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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."""
Expand Down