From 0e9e2ffc96a72c80ae5e8505426fa720ade18982 Mon Sep 17 00:00:00 2001 From: Satellite QE <115476073+Satellite-QE@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:51:38 -0500 Subject: [PATCH] [6.12.z] Pytest FixtureCollection external plugin (#13205) Pytest FixtureCollection external plugin (#13176) (cherry picked from commit a9ffccdae690732f10ea24bd6f9b9ba711b78b47) Co-authored-by: Jitendra Yejare --- conftest.py | 1 - pytest_plugins/fixture_collection.py | 39 ---------------------------- requirements.txt | 1 + 3 files changed, 1 insertion(+), 40 deletions(-) delete mode 100644 pytest_plugins/fixture_collection.py diff --git a/conftest.py b/conftest.py index f64c1e637ce..13e97915232 100644 --- a/conftest.py +++ b/conftest.py @@ -17,7 +17,6 @@ 'pytest_plugins.settings_skip', 'pytest_plugins.rerun_rp.rerun_rp', 'pytest_plugins.fspath_plugins', - 'pytest_plugins.fixture_collection', 'pytest_plugins.factory_collection', 'pytest_plugins.requirements.update_requirements', 'pytest_plugins.sanity_plugin', diff --git a/pytest_plugins/fixture_collection.py b/pytest_plugins/fixture_collection.py deleted file mode 100644 index 6f61f2b3360..00000000000 --- a/pytest_plugins/fixture_collection.py +++ /dev/null @@ -1,39 +0,0 @@ -# Pytest Plugin to modify collection of test cases based on fixtures used by tests. -from robottelo.logging import collection_logger as logger - - -def pytest_addoption(parser): - """Add options for pytest to collect tests based on fixtures its using""" - help_text = ''' - Collects tests based on fixtures used by tests - - Usage: --uses-fixtures [options] - - Options: [ specific_fixture_name | list_of fixture names ] - - example: pytest tests/foreman --uses-fixtures target_sat module_target_sat - ''' - parser.addoption("--uses-fixtures", nargs='?', help=help_text) - - -def pytest_collection_modifyitems(items, config): - - if not config.getoption('uses_fixtures', False): - 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(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 {fixtures_list} used by tests' - ) - config.hook.pytest_deselected(items=deselected) - items[:] = selected diff --git a/requirements.txt b/requirements.txt index fd8a1a41a43..cd58d8a3220 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ pytest-services==2.2.1 pytest-mock==3.12.0 pytest-reportportal==5.3.0 pytest-xdist==3.5.0 +pytest-fixturecollection==0.1.1 pytest-ibutsu==2.2.4 PyYAML==6.0.1 requests==2.31.0