-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathconftest.py
More file actions
72 lines (56 loc) · 2.45 KB
/
Copy pathconftest.py
File metadata and controls
72 lines (56 loc) · 2.45 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Root pytest configuration.
Fast-test filtering
-------------------
By default **all** tests are run.
Pass ``--run-fast`` to skip slow tests and get a quick feedback loop::
pytest --run-fast
Tests are considered slow if they carry ``@pytest.mark.slow`` **or** live
under ``anuga/parallel/tests/`` (MPI-based tests that spawn subprocesses).
To run *only* slow tests::
pytest -m slow
"""
import sys
import pathlib
import pytest
# ---------------------------------------------------------------------------
# Ensure the installed package takes precedence over the source tree.
#
# When pytest loads this conftest.py it inserts the repo root into sys.path
# so that conftest.py itself is importable. That causes `import anuga` to
# resolve to the source tree, which on a fresh clone lacks the meson-
# generated _version.py and raises:
# ModuleNotFoundError: No module named 'anuga._version'
#
# Moving the repo root to the END of sys.path lets site-packages win while
# still keeping the repo root on the path (needed for conftest resolution).
# Editable installs are unaffected: their import hooks still point at src.
# ---------------------------------------------------------------------------
_repo_root = str(pathlib.Path(__file__).parent.resolve())
if _repo_root in sys.path:
sys.path.remove(_repo_root)
sys.path.append(_repo_root)
# ---------------------------------------------------------------------------
# CLI option
# ---------------------------------------------------------------------------
def pytest_addoption(parser):
parser.addoption(
'--run-fast',
action='store_true',
default=False,
help='Skip slow tests (parallel + individually marked) for a quick run.',
)
# ---------------------------------------------------------------------------
# Auto-mark and conditional skip
# ---------------------------------------------------------------------------
def pytest_collection_modifyitems(config, items):
# Auto-mark every test under anuga/parallel/tests/ as slow.
for item in items:
if 'parallel/tests/' in str(item.fspath).replace('\\', '/'):
item.add_marker(pytest.mark.slow)
# Only skip slow tests when --run-fast is explicitly requested.
if not config.getoption('--run-fast'):
return
skip_slow = pytest.mark.skip(reason='slow test — omit --run-fast to include')
for item in items:
if 'slow' in item.keywords:
item.add_marker(skip_slow)