-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
108 lines (91 loc) · 3.82 KB
/
conftest.py
File metadata and controls
108 lines (91 loc) · 3.82 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
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) 2025 OrchIntel Systems Ltd.
# https://orchintel.com | https://ioa.systems
#
# Part of IOA Core (Open Source Edition). See LICENSE at repo root.
"""IOA Core Test Configuration
Pytest configuration and fixtures for IOA Core test suite.
"""
import sys
import os
import importlib.util
import tempfile
from pathlib import Path
# PATCH: Cursor-2025-10-04 DISPATCH-GPT-20251004-002 - Add adapters to Python path for import compatibility
project_root = Path(__file__).parent
adapters_path = project_root / "adapters"
if adapters_path.exists():
sys.path.insert(0, str(adapters_path))
# Create src symlink for backward compatibility
src_link = project_root / "src"
if not src_link.exists() and adapters_path.exists():
try:
os.symlink("adapters", "src")
except OSError:
pass # Symlink may fail on some systems
def _ensure_local_cli_package() -> None:
"""Force `cli` imports to resolve to local `src/cli` package."""
cli_init = project_root / "src" / "cli" / "__init__.py"
if not cli_init.exists():
return
spec = importlib.util.spec_from_file_location(
"cli",
cli_init,
submodule_search_locations=[str(cli_init.parent)],
)
if spec and spec.loader:
module = importlib.util.module_from_spec(spec)
sys.modules["cli"] = module
spec.loader.exec_module(module)
_ensure_local_cli_package()
def _runtime_artifacts_root() -> Path:
"""Return a repo-safe runtime artifacts root outside the tracked tree by default."""
override = os.getenv("IOA_RUNTIME_ARTIFACTS_ROOT")
if override:
return Path(override)
return Path(tempfile.gettempdir()) / "ioa-runtime" / project_root.name
# PATCH: Cursor-2025-08-15 CL-P4-Final-Green - Clean benchmark plugin handling
def pytest_configure(config):
"""Configure pytest to handle plugins cleanly."""
# If this is an xdist worker, disable benchmark plugin cleanly
if hasattr(config, "workerinput"):
# Best-effort disable without emitting warnings
try:
config.option.benchmark_disable = True
except Exception:
import os
os.environ["BENCHMARK_DISABLE"] = "1"
# PATCH: Cursor-2025-08-19 DISPATCH-GPT-20250819-015 <auto full-trace in non-interactive>
import os as _os
if _os.getenv("IOA_NON_INTERACTIVE") == "1":
# Ensure full tracebacks are shown to aid CI triage
try:
config.option.fulltrace = True
except Exception:
pass
# PATCH: Cursor-2025-08-19 DISPATCH-GPT-20250819-015 <write basic pytest report artifacts>
# Minimal report hook to emit a summary file when requested
_report_suite = _os.getenv("IOA_REPORT_SUITE")
if _report_suite == "pytest":
try:
from datetime import datetime, timezone
stamp = datetime.now(timezone.utc).strftime("%Y%m%d-%H%M%S")
_os.environ.setdefault("IOA_REPORT_STAMP", stamp)
_os.environ.setdefault("IOA_RUNTIME_ARTIFACTS_ROOT", str(_runtime_artifacts_root()))
except Exception:
pass
_ensure_local_cli_package()
def pytest_sessionfinish(session, exitstatus):
"""Emit a minimal summary artifact when IOA_REPORT_SUITE=pytest."""
import os as _os
if _os.getenv("IOA_REPORT_SUITE") == "pytest":
try:
from datetime import datetime, timezone
stamp = _os.getenv("IOA_REPORT_STAMP") or datetime.now(timezone.utc).strftime("%Y%m%d-%H%M%S")
out_dir = _runtime_artifacts_root() / "reports" / "pytest" / stamp
out_dir.mkdir(parents=True, exist_ok=True)
summary_path = out_dir / "summary.md"
with open(summary_path, "w", encoding="utf-8") as f:
f.write(f"# Pytest Summary\n\nExit status: {exitstatus}\n")
except Exception:
pass