-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathconftest.py
60 lines (49 loc) · 2.06 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
import pytest
@pytest.fixture(autouse=True)
def run_around_tests():
# Code that will run before your test, for example:
import os
# A test function will be run at this point
yield
# Code that will run after your test, for example:
def pytest_addoption(parser):
parser.addoption(
"--runheavy", action="store_true", default=False, help="run heavy tests"
)
parser.addoption(
"--rungpu", action="store_true", default=False, help="run gpu tests"
)
parser.addoption(
"--rununstable", action="store_true", default=False, help="run unstable tests"
)
def pytest_configure(config):
config.addinivalue_line("markers", "heavy: mark test as heavy to run")
config.addinivalue_line("markers", "gpu: mark test as gpu to run")
config.addinivalue_line("markers", "unstable: mark test as unstable to run")
def pytest_collection_modifyitems(config, items):
if not config.getoption("--runheavy"):
# --runheavy given in cli: do not skip slow tests
skip_heavy = pytest.mark.skip(reason="need --runheavy option to run")
for item in items:
if "heavy" in item.keywords:
item.add_marker(skip_heavy)
else:
skip_heavy = pytest.mark.skip(reason="need --runheavy option to run")
for item in items:
if "heavy" not in item.keywords:
item.add_marker(skip_heavy)
if not config.getoption("--rungpu"):
skip_gpu = pytest.mark.skip(reason="need --rungpu option to run")
for item in items:
if "gpu" in item.keywords:
item.add_marker(skip_gpu)
if not config.getoption("--rununstable"):
skip_unstable = pytest.mark.skip(reason="need --rununstable option to run")
for item in items:
if "unstable" in item.keywords:
item.add_marker(skip_unstable)
else:
skip_unstable = pytest.mark.skip(reason="need --rununstable option to run")
for item in items:
if "unstable" not in item.keywords:
item.add_marker(skip_unstable)