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

Fixture collection splitting restructured #12923

Merged
merged 1 commit into from
Oct 25, 2023
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
7 changes: 4 additions & 3 deletions pytest_plugins/fixture_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def pytest_addoption(parser):

example: pytest tests/foreman --uses-fixtures target_sat module_target_sat
'''
parser.addoption("--uses-fixtures", nargs='+', help=help_text)
parser.addoption("--uses-fixtures", nargs='?', help=help_text)


def pytest_collection_modifyitems(items, config):
Expand All @@ -22,17 +22,18 @@ def pytest_collection_modifyitems(items, config):
return

filter_fixtures = config.getvalue('uses_fixtures')
fixtures_list = filter_fixtures.split(',') if ',' in filter_fixtures else [filter_fixtures]
jyejare marked this conversation as resolved.
Show resolved Hide resolved
selected = []
deselected = []

for item in items:
if set(item.fixturenames).intersection(set(filter_fixtures)):
if set(item.fixturenames).intersection(set(fixtures_list)):
selected.append(item)
else:
deselected.append(item)
logger.debug(
f'Selected {len(selected)} and deselected {len(deselected)} '
f'tests based on given fixtures {filter_fixtures} used by tests'
f'tests based on given fixtures {fixtures_list} used by tests'
)
config.hook.pytest_deselected(items=deselected)
items[:] = selected
Loading