Skip to content

Commit

Permalink
Add --realhw flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Deezzir committed Nov 29, 2024
1 parent ac14150 commit 2422ecb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
26 changes: 12 additions & 14 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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()
Expand All @@ -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."
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 2422ecb

Please sign in to comment.