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
No related branches found
No related tags found
1 merge request!39Improve the test suite
......@@ -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"))
......@@ -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)
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment