From 2422ecb19d99fa0c1dac5c90e0ae30569efc1ce9 Mon Sep 17 00:00:00 2001 From: Deezzir Date: Fri, 29 Nov 2024 17:24:16 -0500 Subject: [PATCH] Add --realhw flag --- tests/functional/conftest.py | 26 ++++++++++++-------------- tests/functional/test_charm.py | 5 +++-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 7f5ba60a..b29025aa 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -19,6 +19,12 @@ def pytest_addoption(parser): help="Set base for the applications.", ) + parser.addoption( + "--realhw", + action="store_true", + help="Enable real hardware testing.", + ) + parser.addoption( "--nvidia", action="store_true", @@ -54,6 +60,11 @@ def nvidia_present(request): return request.config.getoption("--nvidia") +@pytest.fixture(scope="module") +def realhw(request): + return request.config.getoption("--realhw") + + @pytest.fixture(scope="module") def architecture(): machine = platform.machine() @@ -72,20 +83,7 @@ def pytest_configure(config): def pytest_collection_modifyitems(config, items): - if config.getoption("collectors"): - # --collectors provided, skip hw independent tests - skip_hw_independent = pytest.mark.skip( - reason="Hardware independent tests are skipped since --collectors was provided." - ) - for item in items: - # skip TestCharm tests where "realhw" marker is not present - # we don't want to skip test_setup_and_build, test_required_resources, - # test_cos_agent_relation and test_redfish_credential_validation - # even for hw independent tests - # so we also check for the abort_on_fail marker - if "realhw" not in item.keywords and "abort_on_fail" not in item.keywords: - item.add_marker(skip_hw_independent) - else: + if not config.getoption("--realhw"): # skip hw dependent tests in TestCharmWithHW marked with "realhw" skip_hw_dependent = pytest.mark.skip( reason="Hardware dependent test. Provide collectors with the --collectors option." diff --git a/tests/functional/test_charm.py b/tests/functional/test_charm.py index 508ab139..54e23584 100644 --- a/tests/functional/test_charm.py +++ b/tests/functional/test_charm.py @@ -65,7 +65,7 @@ class AppStatus(str, Enum): @pytest.mark.abort_on_fail @pytest.mark.skip_if_deployed async def test_build_and_deploy( # noqa: C901, function is too complex - ops_test: OpsTest, base, architecture, provided_collectors, required_resources, charm_path + ops_test: OpsTest, base, architecture, realhw, required_resources, charm_path ): """Deploy the charm together with related charms. @@ -96,7 +96,7 @@ async def test_build_and_deploy( # noqa: C901, function is too complex # deploy bundle to already added machine instead of provisioning new one # when testing with real hardware - if provided_collectors: + if realhw: juju_cmd.append("--map-machines=existing") logging.info("Deploying bundle...") @@ -168,6 +168,7 @@ async def test_required_resources(ops_test: OpsTest, provided_collectors, requir @pytest.mark.abort_on_fail +@pytest.mark.realhw async def test_nvidia_driver_installation(ops_test: OpsTest, nvidia_present, unit): """Test nvidia driver installation.""" if not nvidia_present: