-
Notifications
You must be signed in to change notification settings - Fork 204
/
conftest.py
38 lines (29 loc) · 900 Bytes
/
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
import pytest
def pytest_addoption(parser):
parser.addoption(
'-B',
'--run-benchmarks',
action='store_true',
default=False,
help='run benchmarks',
)
def pytest_runtest_setup(item):
"""
Skip tests marked benchmark unless --run-benchmark is given to pytest
"""
run_benchmarks = item.config.getoption('--run-benchmarks')
is_benchmark = any(item.iter_markers(name="benchmark"))
if is_benchmark:
if run_benchmarks:
return
pytest.skip(
'need --run-benchmarks to run benchmarks'
)
def pytest_collection_modifyitems(items):
"""
Add the "benchmark" mark to tests that start with "benchmark_".
"""
for item in items:
test_class_name = item.cls.__name__
if test_class_name.startswith("benchmark_"):
item.add_marker(pytest.mark.benchmark)