Skip to content

Commit 09db0b3

Browse files
authored
Refactor conftest.py for clarity and functionality
Updated comments and descriptions for clarity. Adjusted the logic for skipping tests based on the presence of GEMINI_API_KEY.
1 parent 731cd7f commit 09db0b3

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

conftest.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,44 @@
11
"""
2-
Pytest configuration for AST-Healer.
2+
Root conftest.py for AST-Healer.
33
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.
69
"""
710

811
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
1026

1127

1228
def pytest_configure(config):
13-
"""Register custom markers."""
1429
config.addinivalue_line(
1530
"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",
1732
)
1833

1934

2035
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."""
2237
api_key = os.environ.get("GEMINI_API_KEY", "").strip()
2338
if not api_key:
24-
skip_marker = pytest.mark.skip(
39+
skip = pytest.mark.skip(
2540
reason="GEMINI_API_KEY not set — skipping LLM integration tests"
2641
)
2742
for item in items:
2843
if "requires_api_key" in item.keywords:
29-
item.add_marker(skip_marker)
44+
item.add_marker(skip)

0 commit comments

Comments
 (0)