-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathconftest.py
More file actions
57 lines (48 loc) · 1.85 KB
/
Copy pathconftest.py
File metadata and controls
57 lines (48 loc) · 1.85 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
"""*PyTest* configuration and general purpose fixtures."""
import pytest
from pybdm import BDM
from pybdm.partitions import PartitionCorrelated, PartitionRecursive
def pytest_addoption(parser):
"""Custom `pytest` command-line options."""
parser.addoption(
'--benchmarks', action='store_true', default=False,
help="Run benchmarks (instead of tests)."
)
parser.addoption(
'--slow', action='store_true', default=False,
help="Run slow tests / benchmarks."""
)
def pytest_collection_modifyitems(config, items):
"""Modify test runner behaviour based on `pytest` settings."""
run_benchmarks = config.getoption('--benchmarks')
run_slow = config.getoption('--slow')
if run_benchmarks:
skip_test = \
pytest.mark.skip(reason="Only benchmarks are run with --benchmarks")
for item in items:
if 'benchmark' not in item.keywords:
item.add_marker(skip_test)
else:
skip_benchmark = \
pytest.mark.skip(reason="Benchmarks are run only with --run-benchmark")
for item in items:
if 'benchmark' in item.keywords:
item.add_marker(skip_benchmark)
if not run_slow:
skip_slow = pytest.mark.skip(reason="Slow tests are run only with --slow")
for item in items:
if 'slow' in item.keywords:
item.add_marker(skip_slow)
# Fixtures --------------------------------------------------------------------
@pytest.fixture(scope='session')
def bdm_d1():
return BDM(ndim=1)
@pytest.fixture(scope='session')
def bdm_d2():
return BDM(ndim=2)
@pytest.fixture(scope='session')
def bdm_d1_b9():
return BDM(ndim=1, nsymbols=9, partition=PartitionRecursive, min_length=1)
@pytest.fixture(scope='session')
def bdm_d1_collapse3():
return BDM(ndim=1, partition=PartitionCorrelated, shift=3)