forked from scverse/scvi-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
96 lines (78 loc) · 2.8 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
84
85
86
87
88
89
90
91
92
93
94
95
96
import shutil
from distutils.dir_util import copy_tree
import pytest
import torch
import scvi
def pytest_addoption(parser):
"""Docstring for pytest_addoption."""
parser.addoption(
"--model_fit",
action="store_true",
default=False,
dest="model_fit",
help="Option to run full training model for test_model_fit",
)
parser.addoption(
"--internet-tests",
action="store_true",
default=False,
help="Run tests that retrieve stuff from the internet. This increases test time.",
)
parser.addoption(
"--optional",
action="store_true",
default=False,
help="Run tests that are optional.",
)
parser.addoption(
"--cuda",
action="store_true",
default=False,
help="Run tests that required a CUDA backend.",
)
def pytest_configure(config):
"""Docstring for pytest_configure."""
config.addinivalue_line("markers", "optional: mark test as optional.")
def pytest_collection_modifyitems(config, items):
"""Docstring for pytest_collection_modifyitems."""
run_internet = config.getoption("--internet-tests")
skip_internet = pytest.mark.skip(reason="need --internet-tests option to run")
for item in items:
# All tests marked with `pytest.mark.internet` get skipped unless
# `--internet-tests` passed
if not run_internet and ("internet" in item.keywords):
item.add_marker(skip_internet)
run_optional = config.getoption("--optional")
skip_optional = pytest.mark.skip(reason="need --optional option to run")
for item in items:
# All tests marked with `pytest.mark.optional` get skipped unless
# `--optional` passed
if not run_optional and ("optional" in item.keywords):
item.add_marker(skip_optional)
run_cuda = config.getoption("--cuda")
skip_cuda = pytest.mark.skip(reason="need --cuda option to run")
for item in items:
# All tests marked with `pytest.mark.cuda` get skipped unless
# `--cuda` passed
if not run_cuda and ("cuda" in item.keywords):
item.add_marker(skip_cuda)
@pytest.fixture(scope="session")
def save_path(tmpdir_factory):
"""Docstring for save_path."""
dir = tmpdir_factory.mktemp("temp_data", numbered=False)
path = str(dir)
copy_tree("tests/data", path)
yield path + "/"
shutil.rmtree(str(tmpdir_factory.getbasetemp()))
@pytest.fixture(scope="session")
def synthetic_adata():
"""Docstring for model_fit."""
return scvi.data.synthetic_iid()
@pytest.fixture(scope="session")
def model_fit(request):
"""Docstring for model_fit."""
return request.config.getoption("--model_fit")
@pytest.fixture(scope="session")
def cuda():
"""Docstring for cuda."""
assert torch.cuda.is_available()