-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconftest.py
77 lines (61 loc) · 2.11 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
"""
Pytest config for this test directory
https://docs.pytest.org/en/latest/writing_plugins.html#pytest-hook-reference
"""
import pytest
from _pytest.python import Function
def pytest_addoption(parser):
"""
:type parser: _pytest.config.Parser
"""
parser.addini('benchmark_storage', 'Specify a different path to store the runs', type='pathlist')
parser.addini('benchmark_histogram', 'Plot graphs of min/max/avg/stddev over time', type='pathlist')
parser.addoption('--quick-benchmark', action='store_true', help='Run performance check with reduced iteration')
def pytest_cmdline_main(config):
"""
:type config: _pytest.config.Config
"""
if hasattr(config.option, 'benchmark_storage'):
storage_paths = config.getini('benchmark_storage')
if storage_paths:
config.option.benchmark_storage = storage_paths[0].strpath
if hasattr(config.option, 'benchmark_histogram'):
histogram_paths = config.getini('benchmark_histogram')
if histogram_paths:
config.option.benchmark_histogram = histogram_paths
if config.getoption('quick_benchmark'):
config.option.benchmark_max_time = '0.01'
def pytest_itemcollected(item):
"""
:type item: _pytest.main.Node
"""
if item.get_marker('skip'):
__skip_item(item)
def pytest_collection_modifyitems(items):
"""
:type items: list[_pytest.main.Node]
"""
if __has_only_marked_item(items):
__skip_not_only_marked_items(items)
def __has_only_marked_item(items):
"""
:type items: list[_pytest.main.Node]
:rtype: bool
"""
for item in items:
if item.get_marker('only'):
return True
return False
def __skip_not_only_marked_items(items):
"""
:type items: list[_pytest.main.Node]
"""
for item in items:
if type(item) == Function and not item.get_marker('only'): # noqa
__skip_item(item, reason='Skipped by only mark(s)')
def __skip_item(item, reason=None):
"""
:type item: _pytest.main.Node
:type reason: str or None
"""
item.add_marker(pytest.mark.skipif(True, reason=reason))