Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
42 lines (32 loc) · 1.43 KB
/
Copy pathconftest.py
File metadata and controls
42 lines (32 loc) · 1.43 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
"""Keep externally provisioned live tests out of ordinary collection."""
from pathlib import Path
import pytest
def pytest_addoption(parser: pytest.Parser) -> None:
parser.addoption(
"--live",
action="store_true",
default=False,
help="Enable tests/live; requires explicit disposable service configuration",
)
def pytest_configure(config: pytest.Config) -> None:
if config.getoption("--live"):
return
live_root = Path(__file__).parent / "packages/decepticon/tests/live"
for argument in config.args:
selected = Path(argument.split("::", 1)[0]).resolve()
if selected == live_root or live_root in selected.parents:
raise pytest.UsageError("Selecting tests/live requires explicit --live")
def pytest_ignore_collect(collection_path: Path, config: pytest.Config) -> bool | None:
live_root = Path(__file__).parent / "packages/decepticon/tests/live"
if (
collection_path == live_root or live_root in collection_path.parents
) and not config.getoption("--live"):
return True
return None
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
root = Path(__file__).parent / "packages/decepticon/tests"
for item in items:
if root / "live" in item.path.parents:
item.add_marker(pytest.mark.live)
elif root / "integration" in item.path.parents:
item.add_marker(pytest.mark.integration)