-
Notifications
You must be signed in to change notification settings - Fork 4
/
conftest.py
83 lines (76 loc) · 3.26 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# content of conftest.py
import pytest
def pytest_addoption(parser):
parser.addoption(
"--skip_backend", action="store_true", default=False, help="skip backend tests"
)
parser.addoption(
"--run_implicit", action="store_true", default=False, help="run implicit integrator tests"
)
parser.addoption(
"--run_explicit", action="store_true", default=False, help="run explicit integrator tests"
)
parser.addoption(
"--run_torch_gradients", action="store_true", default=False, help="run pytorch gradients integrator tests"
)
parser.addoption(
"--run_gpu", action="store_true", default=False, help="run pytorch gpu tests"
)
parser.addoption(
"--run_cpu", action="store_true", default=True, help="run pytorch cpu tests"
)
def pytest_configure(config):
config.addinivalue_line("markers", "backend: mark test as implicit integrator test")
config.addinivalue_line("markers", "implicit: mark test as implicit integrator test")
config.addinivalue_line("markers", "explicit: mark test as explicit integrator test")
config.addinivalue_line("markers", "torch_gradients: mark test as pytorch gradient test")
config.addinivalue_line("markers", "gpu: mark test as pytorch gpu test")
config.addinivalue_line("markers", "cpu: mark test as pytorch cpu test")
def pytest_collection_modifyitems(config, items):
if config.getoption("--skip_backend"):
skip_backend = pytest.mark.skip(reason="backend tests marked as skip")
for item in items:
if "backend" in item.keywords:
item.add_marker(skip_backend)
else:
pass
if config.getoption("--run_implicit"):
# --run_implicit given in cli: do not skip implicit integrator tests
pass
else:
skip_implicit = pytest.mark.skip(reason="need --run_implicit option to run")
for item in items:
if "implicit" in item.keywords:
item.add_marker(skip_implicit)
if config.getoption("--run_explicit"):
# --run_explicit given in cli: do not skip explicit integrator tests
pass
else:
skip_explicit = pytest.mark.skip(reason="need --run_explicit option to run")
for item in items:
if "explicit" in item.keywords:
item.add_marker(skip_explicit)
if config.getoption("--run_torch_gradients"):
# --run_torch_gradients given in cli: do not skip tests for pytorch gradients
pass
else:
skip_torch_gradients = pytest.mark.skip(reason="need --run_torch_gradients option to run")
for item in items:
if "torch_gradients" in item.keywords:
item.add_marker(skip_torch_gradients)
if config.getoption("--run_gpu"):
# --run_gpu given in cli: do not skip cuda device tests
pass
else:
gpu = pytest.mark.skip(reason="need --run_gpu option to run")
for item in items:
if "gpu" in item.keywords:
item.add_marker(gpu)
if config.getoption("--run_cpu"):
# --run_cpu given in cli: do not skip cpu tests
pass
else:
cpu = pytest.mark.skip(reason="need --run_cpu option to run")
for item in items:
if "cpu" in item.keywords:
item.add_marker(cpu)