From 4b27ae5a046e70b8c14bb2843b2fc078687f1ce4 Mon Sep 17 00:00:00 2001 From: Jacob Callahan Date: Tue, 14 Nov 2023 09:49:21 -0500 Subject: [PATCH] Add basic fixture cli This change adds a new fixture_cli.py script under the scripts directory. The basic usage of this script is to take in a space-separated list of global fixtures and run them together in a single temporary test. e.g. python scripts/fixture_cli.py module_ak_with_synced_repo module_lce Additionally, I had to make some minor adjustments to a couple of plugins since this temporary test doesn't follow the same rules as the rest of our framework. --- pytest_plugins/fspath_plugins.py | 5 +++-- pytest_plugins/issue_handlers.py | 4 +++- scripts/fixture_cli.py | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 scripts/fixture_cli.py diff --git a/pytest_plugins/fspath_plugins.py b/pytest_plugins/fspath_plugins.py index 316d066a6b0..81b1d35b45e 100644 --- a/pytest_plugins/fspath_plugins.py +++ b/pytest_plugins/fspath_plugins.py @@ -12,5 +12,6 @@ def pytest_collection_modifyitems(session, items, config): if item.nodeid.startswith('tests/robottelo/') or item.nodeid.startswith('tests/upgrades/'): continue - endpoint = endpoint_regex.findall(item.location[0])[0] - item.user_properties.append(('endpoint', endpoint)) + endpoints = endpoint_regex.findall(item.location[0]) + if endpoints: + item.user_properties.append(('endpoint', endpoints[0])) diff --git a/pytest_plugins/issue_handlers.py b/pytest_plugins/issue_handlers.py index 3da2044faff..614c75a45be 100644 --- a/pytest_plugins/issue_handlers.py +++ b/pytest_plugins/issue_handlers.py @@ -214,7 +214,9 @@ def generate_issue_collection(items, config): # pragma: no cover filepath, lineno, testcase = item.location # Component and importance marks are determined by testimony tokens # Testimony.yaml as of writing has both as required, so any - component_mark = item.get_closest_marker('component').args[0] + if not (components := item.get_closest_marker('component')): + continue + component_mark = components.args[0] component_slug = slugify_component(component_mark, False) importance_mark = item.get_closest_marker('importance').args[0] for marker in item.iter_markers(): diff --git a/scripts/fixture_cli.py b/scripts/fixture_cli.py new file mode 100644 index 00000000000..e34930ab197 --- /dev/null +++ b/scripts/fixture_cli.py @@ -0,0 +1,24 @@ +from pathlib import Path + +import click +import pytest + + +@click.command() +@click.argument("fixtures", nargs=-1, required=True) +def run_fixtures(fixtures): + """Create a temporary test that depends on each fixture, then run it. + + Example: python scripts/fixture_cli.py module_published_cv module_subscribe_satellite + """ + fixture_string = ", ".join(filter(None, fixtures)) + test_template = "def test_fake({}):\n assert True" + test_template = test_template.format(fixture_string) + temp_file = Path("test_DELETEME.py") + temp_file.write_text(test_template) + pytest.main(["-qq", str(temp_file)]) + temp_file.unlink() + + +if __name__ == "__main__": + run_fixtures()