Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
67 lines (52 loc) · 1.95 KB
/
Copy pathconftest.py
File metadata and controls
67 lines (52 loc) · 1.95 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
"""Repo-root pytest configuration.
CI invokes pytest as a console script, which does not place the working
directory on ``sys.path``. Tests that exercise the F0 migration tooling
import the ``tools.us_bundle_generation`` package from the repository
root, so the root joins the path here explicitly rather than by the
accident of ``python -m pytest``.
"""
import importlib.util
import sys
from pathlib import Path
_ROOT = str(Path(__file__).resolve().parent)
if _ROOT not in sys.path:
sys.path.insert(0, _ROOT)
from tools.ci_test_plan import ( # noqa: E402
TEST_GROUPS,
TestGroup,
group_name_for_collection_path,
)
def pytest_addoption(parser) -> None:
parser.addoption(
"--run-integration",
action="store_true",
default=False,
help="collect tests under tests/integration/",
)
def _test_group(path: Path) -> TestGroup | None:
"""Return registry metadata for the group containing a collection path."""
group = group_name_for_collection_path(path)
return TEST_GROUPS.get(group) if group is not None else None
def pytest_ignore_collect(collection_path: Path, config) -> bool | None:
"""Exclude unavailable test environments before importing their modules."""
group = _test_group(Path(collection_path))
if group is None:
return None
if group.integration and not config.getoption("--run-integration"):
return True
if (
group.engine_module is not None
and importlib.util.find_spec(group.engine_module) is None
):
return True
return None
def pytest_collection_modifyitems(items) -> None:
"""Expose directory-derived country requirements as pytest markers."""
for item in items:
group = _test_group(Path(item.path))
if group is None:
continue
if group.integration:
item.add_marker("integration")
if group.engine_module is not None:
item.add_marker(f"requires_{group.country}")