Mentions légales du service

Skip to content
Snippets Groups Projects
Verified Commit 5fe5ed7c authored by ANDREY Paul's avatar ANDREY Paul
Browse files

Add a '--cpu-only' mode for unit tests.

parent 45def4ed
Branches
Tags
1 merge request!39Improve the test suite
...@@ -20,17 +20,29 @@ ...@@ -20,17 +20,29 @@
import pytest import pytest
def pytest_addoption(parser) -> None: # type: ignore def pytest_addoption(parser) -> None:
"""Add a '--fulltest' option to the pytest commandline.""" """Add some custom options to the pytest commandline."""
parser.addoption( parser.addoption(
"--fulltest", "--fulltest",
action="store_true", action="store_true",
default=False, default=False,
help="--fulltest: run all test scenarios in 'test_main.py'", 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") @pytest.fixture(name="fulltest")
def fulltest_fixture(request) -> bool: # type: ignore def fulltest_fixture(request) -> bool:
"""Gather the '--fulltest' option's value.""" """Gather the '--fulltest' option's value."""
return bool(request.config.getoption("--fulltest")) 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"))
...@@ -159,8 +159,11 @@ class TensorflowTestCase(ModelTestCase): ...@@ -159,8 +159,11 @@ class TensorflowTestCase(ModelTestCase):
def fixture_test_case( def fixture_test_case(
kind: Literal["MLP", "MLP-tune", "RNN", "CNN"], kind: Literal["MLP", "MLP-tune", "RNN", "CNN"],
device: Literal["CPU", "GPU"], device: Literal["CPU", "GPU"],
cpu_only: bool,
) -> TensorflowTestCase: ) -> TensorflowTestCase:
"""Fixture to access a TensorflowTestCase.""" """Fixture to access a TensorflowTestCase."""
if cpu_only and (device == "GPU"):
pytest.skip(reason="--cpu-only mode")
return TensorflowTestCase(kind, device) return TensorflowTestCase(kind, device)
......
...@@ -176,8 +176,11 @@ class TorchTestCase(ModelTestCase): ...@@ -176,8 +176,11 @@ class TorchTestCase(ModelTestCase):
def fixture_test_case( def fixture_test_case(
kind: Literal["MLP", "MLP-tune", "RNN", "CNN"], kind: Literal["MLP", "MLP-tune", "RNN", "CNN"],
device: Literal["CPU", "GPU"], device: Literal["CPU", "GPU"],
cpu_only: bool,
) -> TorchTestCase: ) -> TorchTestCase:
"""Fixture to access a TorchTestCase.""" """Fixture to access a TorchTestCase."""
if cpu_only and device == "GPU":
pytest.skip(reason="--cpu-only mode")
return TorchTestCase(kind, device) return TorchTestCase(kind, device)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment