Skip to content

Commit

Permalink
Fixture collection splitting restructured (#12923)
Browse files Browse the repository at this point in the history
Fixture collection spliting restructured

(cherry picked from commit 33f4b32)
  • Loading branch information
jyejare authored and web-flow committed Oct 25, 2023
1 parent 43598ac commit 59da053
Showing 1 changed file with 4 additions and 3 deletions.
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]
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

0 comments on commit 59da053

Please sign in to comment.