diff --git a/test/conftest.py b/test/conftest.py index 5d51c2c90bb87f3062215fc1a537281c810a3e19..dfc786f240829604ef1012a072a5d622b276e692 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -20,17 +20,29 @@ import pytest -def pytest_addoption(parser) -> None: # type: ignore - """Add a '--fulltest' option to the pytest commandline.""" +def pytest_addoption(parser) -> None: + """Add some custom options to the pytest commandline.""" parser.addoption( "--fulltest", action="store_true", default=False, help="--fulltest: run all test scenarios in 'test_main.py'", ) + parser.addoption( + "--cpu-only", + action="store_true", + default=False, + help="--cpu-only: disable the use of GPU devices in tests", + ) @pytest.fixture(name="fulltest") -def fulltest_fixture(request) -> bool: # type: ignore +def fulltest_fixture(request) -> bool: """Gather the '--fulltest' option's value.""" return bool(request.config.getoption("--fulltest")) + + +@pytest.fixture(name="cpu_only") +def cpu_only_fixture(request) -> bool: + """Gather the '--cpu-only' option's value.""" + return bool(request.config.getoption("--cpu-only")) diff --git a/test/model/test_tflow.py b/test/model/test_tflow.py index aefd62e45489b2e264babbc69830fec68458147b..2e89fb4c71f1f129a2ed2ab3d7d7eb014640bc14 100644 --- a/test/model/test_tflow.py +++ b/test/model/test_tflow.py @@ -159,8 +159,11 @@ class TensorflowTestCase(ModelTestCase): def fixture_test_case( kind: Literal["MLP", "MLP-tune", "RNN", "CNN"], device: Literal["CPU", "GPU"], + cpu_only: bool, ) -> TensorflowTestCase: """Fixture to access a TensorflowTestCase.""" + if cpu_only and (device == "GPU"): + pytest.skip(reason="--cpu-only mode") return TensorflowTestCase(kind, device) diff --git a/test/model/test_torch.py b/test/model/test_torch.py index 15031107378231ef5b1a4ec62714da1e7988a53e..41e60a8bb8d1e389fceae03678c7ac1cbc06ef73 100644 --- a/test/model/test_torch.py +++ b/test/model/test_torch.py @@ -176,8 +176,11 @@ class TorchTestCase(ModelTestCase): def fixture_test_case( kind: Literal["MLP", "MLP-tune", "RNN", "CNN"], device: Literal["CPU", "GPU"], + cpu_only: bool, ) -> TorchTestCase: """Fixture to access a TorchTestCase.""" + if cpu_only and device == "GPU": + pytest.skip(reason="--cpu-only mode") return TorchTestCase(kind, device)