-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconftest.py
More file actions
87 lines (71 loc) · 2.28 KB
/
Copy pathconftest.py
File metadata and controls
87 lines (71 loc) · 2.28 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from __future__ import annotations
import random
import numpy as np
import pytest
def pytest_addoption(parser: pytest.Parser) -> None:
"""
Register custom command-line options for pytest.
"""
parser.addoption(
"--run-slow",
action="store_true",
default=False,
help="Run slow regression tests (20-30+ minutes).",
)
parser.addoption(
"--update-baselines",
action="store_true",
default=False,
help="Overwrite regression baselines with the newly produced outputs.",
)
parser.addoption(
"--codeentropy-debug",
action="store_true",
default=False,
help="Print CodeEntropy stdout/stderr and paths for easier debugging.",
)
parser.addoption(
"--system",
action="append",
default=None,
help="Run only tests for specified system(s). Can be passed multiple times.",
)
def pytest_configure(config: pytest.Config) -> None:
"""
Register markers and enforce deterministic behavior.
"""
config.addinivalue_line("markers", "regression: end-to-end regression tests")
config.addinivalue_line("markers", "slow: long-running tests (20-30+ minutes)")
seed = 0
random.seed(seed)
np.random.seed(seed)
def pytest_collection_modifyitems(
config: pytest.Config, items: list[pytest.Item]
) -> None:
"""
Modify collected test items to:
1. Skip slow tests unless --run-slow is provided
2. Filter tests by --system if specified
"""
if not config.getoption("--run-slow"):
skip_slow = pytest.mark.skip(
reason="Skipped slow test (use --run-slow to run)."
)
for item in items:
if "slow" in item.keywords:
item.add_marker(skip_slow)
selected_systems = config.getoption("--system")
if not selected_systems:
return
filtered_items = []
for item in items:
callspec = getattr(item, "callspec", None)
case = None
if callspec is not None:
case = callspec.params.get("case")
if case is None:
filtered_items.append(item)
continue
if hasattr(case, "system") and case.system in selected_systems:
filtered_items.append(item)
items[:] = filtered_items