-
Notifications
You must be signed in to change notification settings - Fork 10
/
conftest.py
51 lines (42 loc) · 1.74 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
"""Configuration for pytest.
It's needed here to add the option `--runslow`, which is mainly used in the lattice
subpackage.
"""
import pytest
import pathlib
def pytest_addoption(parser):
"""Add option '--runslow' and '--rungmsh'."""
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)
parser.addoption(
"--rungmsh", action="store_true", default=False, help="run tests needing gmsh"
)
parser.addini("datadir", "my own datadir for pytest-regressions")
parser.addini("original_datadir", "my own original_datadir for pytest-regressions")
def pytest_configure(config):
"""Add marker 'slow' and 'gmsh'."""
config.addinivalue_line("markers", "gmsh: test needs gmsh")
config.addinivalue_line("markers", "slow: mark test as slow to run")
def pytest_collection_modifyitems(config, items):
"""Skip tests without necessary options."""
if not config.getoption("--runslow"):
# --runslow not given in cli: skip slow tests
skip_slow = pytest.mark.skip(reason="need --runslow option to run")
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
if not config.getoption("--rungmsh"):
# --rungmsh not given in cli: skip gmsh tests
skip_slow = pytest.mark.skip(reason="need --rungmsh option to run")
for item in items:
if "gmsh" in item.keywords:
item.add_marker(skip_slow)
@pytest.fixture()
def original_datadir(request) -> pathlib.Path:
config = request.config
return config.rootpath / config.getini('datadir')
@pytest.fixture()
def datadir(request) -> pathlib.Path:
config = request.config
return config.rootpath / config.getini('datadir')