|
1 | 1 | """ |
2 | | -Pytest configuration for AST-Healer. |
| 2 | +Root conftest.py for AST-Healer. |
3 | 3 |
|
4 | | -Tests that invoke the Gemini API are skipped automatically in CI |
5 | | -when GEMINI_API_KEY is not set as a repository secret. |
| 4 | +Executed by pytest before any test collection. Handles two things: |
| 5 | +1. Injects the google.antigravity stub into sys.path so CI can import |
| 6 | + main.py and app.py without the real Gemini SDK installed. |
| 7 | +2. Auto-skips any test marked @pytest.mark.requires_api_key when |
| 8 | + GEMINI_API_KEY is absent. |
6 | 9 | """ |
7 | 10 |
|
8 | 11 | import os |
9 | | -import pytest |
| 12 | +import sys |
| 13 | +from pathlib import Path |
| 14 | + |
| 15 | +# Inject the google.antigravity stub BEFORE any project module is imported. |
| 16 | +# The stub lives at tests/mocks/ and is only activated when the real package is not already installed. |
| 17 | +try: |
| 18 | + import google.antigravity # noqa: F401 — real package found, nothing to do |
| 19 | +except ImportError: |
| 20 | + stub_path = str(Path(__file__).parent / "tests" / "mocks") |
| 21 | + if stub_path not in sys.path: |
| 22 | + sys.path.insert(0, stub_path) |
| 23 | + |
| 24 | +# Custom markers |
| 25 | +import pytest # noqa: E402 — must come after path manipulation |
10 | 26 |
|
11 | 27 |
|
12 | 28 | def pytest_configure(config): |
13 | | - """Register custom markers.""" |
14 | 29 | config.addinivalue_line( |
15 | 30 | "markers", |
16 | | - "requires_api_key: mark test as requiring GEMINI_API_KEY to run", |
| 31 | + "requires_api_key: skip this test when GEMINI_API_KEY is not set", |
17 | 32 | ) |
18 | 33 |
|
19 | 34 |
|
20 | 35 | def pytest_collection_modifyitems(config, items): |
21 | | - """Skip LLM tests when API key is absent.""" |
| 36 | + """Auto-skip LLM integration tests in CI when no API key is present.""" |
22 | 37 | api_key = os.environ.get("GEMINI_API_KEY", "").strip() |
23 | 38 | if not api_key: |
24 | | - skip_marker = pytest.mark.skip( |
| 39 | + skip = pytest.mark.skip( |
25 | 40 | reason="GEMINI_API_KEY not set — skipping LLM integration tests" |
26 | 41 | ) |
27 | 42 | for item in items: |
28 | 43 | if "requires_api_key" in item.keywords: |
29 | | - item.add_marker(skip_marker) |
| 44 | + item.add_marker(skip) |
0 commit comments