From a9ffccdae690732f10ea24bd6f9b9ba711b78b47 Mon Sep 17 00:00:00 2001 From: Jitendra Yejare Date: Wed, 29 Nov 2023 15:09:27 +0530 Subject: [PATCH] Pytest FixtureCollection external plugin (#13176) --- 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 632f6e2a0e4..4b8575813ee 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 ded6006ea87..4cead800f56 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,6 +18,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