-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathconftest.py
More file actions
87 lines (69 loc) · 2.51 KB
/
Copy pathconftest.py
File metadata and controls
87 lines (69 loc) · 2.51 KB
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
import pytest
# Import all fixtures from list of plugins
pytest_plugins = [
"tests.list_of_dicts.lod_fixtures",
"tests.patterns.patterns_fixtures",
]
SKIP = {
"short": ["download", "ftp", "long_test", "ecfs", "migrate", "legacy"],
"long": ["ftp", "ecfs", "migrate", "legacy"],
"release": ["migrate", "legacy"],
"legacy": ["download", "ftp", "long_test", "ecfs", "migrate"],
"migrate": ["download", "ftp", "long_test", "ecfs", "legacy"],
"documentation": None,
}
def pytest_configure(config):
pytest.CDS_TIMEOUT = config.getoption("--cds-timeout")
def pytest_addoption(parser):
help_str = "NAME: short, long, release, documentation. Runs a subset of tests.\n"
for k, v in SKIP.items():
if v:
help_str += f"'{k}': skip tests marked as {','.join(v)}.\n"
else:
help_str += f"'{k}': do not skip tests.\n"
parser.addoption(
"-E",
action="store",
metavar="NAME",
default="short",
help=help_str,
)
parser.addoption(
"--cds-timeout",
action="store",
metavar="TIMEOUT",
default=30,
help="Timeout in seconds for cds tests. 0 means no timeout. Default is 30.",
)
def pytest_runtest_setup(item):
# print(f"config {item.config.option}")
flag = item.config.getoption("-E")
marks_to_skip = SKIP[flag]
marks_in_items = list([m.name for m in item.iter_markers()])
if marks_to_skip is None:
if flag not in marks_in_items:
pytest.skip(f"test is skipped because custom pytest option : -E {flag}")
return
for m in marks_in_items:
if m in marks_to_skip:
pytest.skip(f"test is skipped because custom pytest option: -E {flag}")
marked_no_cache_init = "no_cache_init" in marks_in_items
if marked_no_cache_init and not item.config.getoption("--forked"):
pytest.skip("test is skipped because marked as no_cache_init but --forked is not used")
need_cache = "cache" in marks_in_items
# settings
from earthkit.data import config
# ensure settings are not saved automatically
config.autosave = False
# ensure all the tests use the default settings
if marked_no_cache_init:
# do not broadcast setting changes, otherwise
# the cache would be initialised
config._notify_enabled = False
config.reset()
config._notify_enabled = True
elif need_cache:
config.reset()
config.set("cache-policy", "user")
else:
config.reset()