-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathconftest.py
66 lines (50 loc) · 1.58 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
from pathlib import Path
import pytest
import torch
import flair
@pytest.fixture(scope="module")
def resources_path():
return Path(__file__).parent / "resources"
@pytest.fixture(scope="module")
def tasks_base_path(resources_path):
return resources_path / "tasks"
@pytest.fixture()
def results_base_path(resources_path):
path = resources_path / "results"
try:
yield path
finally:
for p in reversed(list(path.rglob("*"))):
if p.is_file():
p.unlink()
else:
p.rmdir()
if path.is_dir():
path.rmdir()
@pytest.fixture(autouse=True)
def set_cpu(force_cpu):
if force_cpu:
flair.device = torch.device("cpu")
def pytest_addoption(parser):
parser.addoption(
"--runintegration",
action="store_true",
default=False,
help="run integration tests",
)
parser.addoption(
"--force-cpu",
action="store_true",
default=False,
help="use cpu for tests even when gpu is available",
)
def pytest_collection_modifyitems(config, items):
if not config.getoption("--runintegration"):
skip_integration = pytest.mark.skip(reason="need --runintegration option to run")
for item in items:
if "integration" in item.keywords:
item.add_marker(skip_integration)
def pytest_generate_tests(metafunc):
option_value = metafunc.config.getoption("--force-cpu")
if "force_cpu" in metafunc.fixturenames and option_value is not None:
metafunc.parametrize("force_cpu", [option_value])