forked from Alishahryar1/free-claude-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
126 lines (93 loc) · 3.61 KB
/
Copy pathconftest.py
File metadata and controls
126 lines (93 loc) · 3.61 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from collections.abc import Iterator
from typing import Any
import pytest
from smoke.lib.config import ProviderModel, SmokeConfig, auth_headers
from smoke.lib.report import SmokeReport
from smoke.lib.server import RunningServer, start_server
DISABLED_PROVIDER_MODEL = ProviderModel(
provider="smoke_disabled",
full_model="smoke_disabled/smoke-disabled",
source="smoke_disabled",
)
def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
if "provider_model" in metafunc.fixturenames:
config = SmokeConfig.load()
metafunc.parametrize("provider_model", provider_model_params(config))
def pytest_collection_modifyitems(items: list[pytest.Item]) -> None:
if SmokeConfig.load().live:
return
skip = pytest.mark.skip(reason="set FCC_LIVE_SMOKE=1 to run local smoke tests")
for item in items:
item.add_marker(skip)
def pytest_configure(config: pytest.Config) -> None:
global _REPORT
smoke_config = SmokeConfig.load()
_REPORT = SmokeReport(smoke_config)
def pytest_runtest_setup(item: pytest.Item) -> None:
config = SmokeConfig.load()
target_marks = list(item.iter_markers("smoke_target"))
if not target_marks:
return
targets = [str(mark.args[0]) for mark in target_marks if mark.args]
if targets and not any(config.target_enabled(target) for target in targets):
pytest.skip(f"smoke target disabled: {', '.join(targets)}")
def pytest_runtest_logreport(report: pytest.TestReport) -> None:
if report.when == "setup" and not report.skipped:
return
if report.when == "teardown" and not report.failed:
return
if _REPORT is None:
return
markers = sorted(
str(name) for name in report.keywords if str(name).startswith("smoke_")
)
detail = "" if report.longrepr is None else str(report.longrepr)
_REPORT.add(
nodeid=report.nodeid,
outcome=report.outcome,
duration_s=report.duration,
markers=markers,
detail=detail,
)
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
if _REPORT is not None:
_REPORT.write()
@pytest.fixture(scope="session")
def smoke_config() -> SmokeConfig:
return SmokeConfig.load()
@pytest.fixture
def smoke_server(smoke_config: SmokeConfig) -> Iterator[RunningServer]:
with start_server(smoke_config) as server:
yield server
@pytest.fixture
def smoke_headers() -> dict[str, str]:
return auth_headers()
def provider_model_params(config: SmokeConfig) -> list[Any]:
"""Return provider params grouped for pytest-xdist ``--dist=loadgroup``."""
if not config.live:
return [_disabled_provider_param("set FCC_LIVE_SMOKE=1 to run provider smoke")]
models = config.provider_smoke_models()
if not models:
return [_disabled_provider_param("missing_env: no configured provider smoke")]
return [
pytest.param(
model,
id=provider_model_id(model),
marks=pytest.mark.xdist_group(provider_xdist_group(model)),
)
for model in models
]
def _disabled_provider_param(reason: str) -> Any:
return pytest.param(
DISABLED_PROVIDER_MODEL,
id=provider_model_id(DISABLED_PROVIDER_MODEL),
marks=(
pytest.mark.skip(reason=reason),
pytest.mark.xdist_group(provider_xdist_group(DISABLED_PROVIDER_MODEL)),
),
)
def provider_model_id(provider_model: ProviderModel) -> str:
return provider_model.provider
def provider_xdist_group(provider_model: ProviderModel) -> str:
return f"provider:{provider_model.provider}"
_REPORT: SmokeReport | None = None