This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
87 lines (71 loc) · 2.76 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
"""PyTest local plugins."""
import os
import pytest
SKIPPING_CONFIG = {
"slow": {
"option": "--run-only-slow",
"help": "run only the slow tests",
"description": "mark test as slow to run",
"skip_otherwise": True,
},
"yarn": {
"option": "--run-only-yarn",
"help": "run only the tests that need yarn",
"description": "mark test as needing yarn",
"skip_otherwise": True,
},
"pydicom": {
"option": "--run-only-pydicom",
"help": "run only the tests that use pydicom",
"description": "mark test as using pydicom",
"skip_otherwise": False,
},
"pylinac": {
"option": "--run-only-pylinac",
"help": "run only the tests that use pylinac",
"description": "mark test as using pylinac",
"skip_otherwise": False,
},
}
# https://docs.pytest.org/en/latest/example/simple.html#control-skipping-of-tests-according-to-command-line-option
def pytest_addoption(parser):
for _, skip_item in SKIPPING_CONFIG.items():
parser.addoption(
skip_item["option"],
action="store_true",
default=False,
help=skip_item["help"],
)
def pytest_configure(config):
for key, skip_item in SKIPPING_CONFIG.items():
config.addinivalue_line("markers", f"{key}: {skip_item['description']}")
def pytest_collection_modifyitems(config, items):
for key, skip_item in SKIPPING_CONFIG.items():
if not config.getoption(skip_item["option"]):
if skip_item["skip_otherwise"]:
skip = pytest.mark.skip(
reason=f"need {skip_item['option']} option to run"
)
for item in items:
if key in item.keywords:
item.add_marker(skip)
else:
skip = pytest.mark.skip(reason=f"since {skip_item['option']} was passed")
for item in items:
if key not in item.keywords:
item.add_marker(skip)
def pytest_ignore_collect(path, config): # pylint: disable = unused-argument
"""return True to prevent considering this path for collection.
This hook is consulted for all files and directories prior to
calling more specific hooks.
"""
relative_path = os.path.relpath(str(path), os.path.dirname(__file__))
relative_path_list = relative_path.split(os.path.sep)
return (
(len(relative_path_list) > 1 and relative_path_list[0] == "examples")
or "node_modules" in relative_path_list
or "site-packages" in relative_path_list
or ("_bundle" in relative_path_list and "python" in relative_path_list)
or config.getoption("--doctest-modules")
and "streamlit" in relative_path_list
)