Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to collect test cases by supported topology #2640

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
27 changes: 19 additions & 8 deletions tests/common/plugins/custom_markers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ def pytest_configure(config):
"markers", "supported_completeness_level(TEST_LEVEL): mark test to specify the completeness level for the test. Allowed values: 'debug', 'basic' ,'confident', 'thorough'"
)

def pytest_collection_modifyitems(session):
if session.config.getoption("--topology"):
for item in session.items[:]:
check_topology(session, item)

def pytest_runtest_setup(item):
if item.config.getoption("--topology"):
check_topology(item)
if item.config.getoption("--feature"):
check_feature(item)
if item.config.getoption("--asic"):
Expand All @@ -55,19 +58,27 @@ def pytest_runtest_setup(item):

check_test_completeness(item)

def check_topology(item):
def check_topology(session, item):
# The closest marker is used here so that the module or class level
# marker will be overrided by case level marker
topo_marks = [mark for mark in item.iter_markers(name="topology")] # Get all 'topology' marks on the chain
if topo_marks:
topo_mark = topo_marks[0] # The nearest mark overides others
cfg_topos = item.config.getoption("--topology").split(',')
cfg_topos = session.config.getoption("--topology").split(',')
if all(topo not in topo_mark.args for topo in cfg_topos):
pytest.skip("test requires topology in {!r}".format(topo_mark))
if session.config.getoption("--collectonly"):
session.items.remove(item)
session.config.hook.pytest_deselected(items=[item])
else:
item.add_marker(pytest.mark.skip("test requires topology in {!r}".format(topo_mark)))
else:
warn_msg = "testcase {} is skipped when no topology marker is given".format(item.nodeid)
warnings.warn(warn_msg)
pytest.skip(warn_msg)
if session.config.getoption("--collectonly"):
session.items.remove(item)
session.config.hook.pytest_deselected(items=[item])
else:
warn_msg = "testcase {} is skipped when no topology marker is given".format(item.nodeid)
warnings.warn(warn_msg)
item.add_marker(pytest.mark.skip(warn_msg))

def check_feature(item):
feature_names = [mark.args for mark in item.iter_markers(name="feature")]
Expand Down