-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathconftest.py
52 lines (40 loc) · 1.77 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
import pytest
import matplotlib
import plotly
plotly.io.renderers.default = None
matplotlib.use("Template")
def pytest_addoption(parser):
parser.addoption(
"--unit", action="store_true", default=False, help="run unit tests"
)
parser.addoption(
"--examples", action="store_true", default=False, help="run examples tests"
)
def pytest_terminal_summary(terminalreporter, exitstatus, config):
"""Add additional section to terminal summary reporting."""
total_time = sum([x.duration for x in terminalreporter.stats.get("passed", [])])
num_tests = len(terminalreporter.stats.get("passed", []))
print(f"\nTotal number of tests completed: {num_tests}")
print(f"Total time taken: {total_time:.2f} seconds")
def pytest_configure(config):
config.addinivalue_line("markers", "unit: mark test as a unit test")
config.addinivalue_line("markers", "examples: mark test as an example")
def pytest_collection_modifyitems(config, items):
unit_option = config.getoption("--unit")
examples_option = config.getoption("--examples")
if not unit_option and not examples_option:
skip_all = pytest.mark.skip(reason="need --unit or --examples option to run")
for item in items:
item.add_marker(skip_all)
elif unit_option and not examples_option:
skip_examples = pytest.mark.skip(
reason="need --examples option to run examples tests"
)
for item in items:
if "examples" in item.keywords:
item.add_marker(skip_examples)
if examples_option and not unit_option:
skip_unit = pytest.mark.skip(reason="need --unit option to run unit tests")
for item in items:
if "unit" in item.keywords:
item.add_marker(skip_unit)