Skip to content

Commit

Permalink
[6.12.z] Fixture collection splitting restructured (#12979)
Browse files Browse the repository at this point in the history
Fixture collection splitting restructured (#12923)

Fixture collection spliting restructured

(cherry picked from commit 33f4b32)

Co-authored-by: Jitendra Yejare <[email protected]>
  • Loading branch information
Satellite-QE and jyejare authored Oct 26, 2023
1 parent d5d6150 commit dacd129
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 dacd129

Please sign in to comment.