Skip to content

Commit 491a135

Browse files
AndyMik90claude
andcommitted
fix(tests): address PR review feedback
- Remove unused imports (AsyncMock, patch) from test_spec_complexity.py - Remove unused MagicMock import from test_spec_pipeline.py - Move inline 'import os' to module level in test_spec_pipeline.py - Rename _API_KEY_ENV_VARS to _ENV_VARS_TO_CLEAR with clarifying comment - Add separate check for 'google' namespace before overwriting - Remove redundant sys import from mock_graphiti_providers fixture Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e39a4d2 commit 491a135

3 files changed

Lines changed: 9 additions & 14 deletions

File tree

‎tests/conftest.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def _create_sdk_mock():
4444

4545
# Pre-mock google.generativeai if not installed
4646
if 'google.generativeai' not in sys.modules:
47-
sys.modules['google'] = MagicMock()
47+
if 'google' not in sys.modules:
48+
sys.modules['google'] = MagicMock()
4849
sys.modules['google.generativeai'] = MagicMock()
4950

5051
# Add apps/backend directory to path for imports
@@ -167,16 +168,17 @@ def pytest_runtest_setup(item):
167168
# ENVIRONMENT SAFEGUARDS - Prevent real API calls during tests
168169
# =============================================================================
169170

170-
# API key environment variables that should be cleared during tests
171-
_API_KEY_ENV_VARS = [
171+
# Environment variables that should be cleared during tests to prevent real API calls.
172+
# Includes API keys, OAuth tokens, and feature flags that enable external services.
173+
_ENV_VARS_TO_CLEAR = [
172174
'ANTHROPIC_API_KEY',
173175
'OPENAI_API_KEY',
174176
'CLAUDE_CODE_OAUTH_TOKEN',
175177
'GOOGLE_API_KEY',
176178
'AZURE_OPENAI_API_KEY',
177179
'AZURE_OPENAI_ENDPOINT',
178180
'VOYAGE_API_KEY',
179-
'GRAPHITI_ENABLED',
181+
'GRAPHITI_ENABLED', # Feature flag - also cleared to prevent Graphiti initialization
180182
'LINEAR_API_KEY',
181183
'GITHUB_TOKEN',
182184
]
@@ -194,7 +196,7 @@ def prevent_real_api_calls(monkeypatch):
194196
The original environment is automatically restored after each test by
195197
pytest's monkeypatch fixture.
196198
"""
197-
for env_var in _API_KEY_ENV_VARS:
199+
for env_var in _ENV_VARS_TO_CLEAR:
198200
monkeypatch.delenv(env_var, raising=False)
199201

200202

@@ -895,7 +897,6 @@ class MockProviderNotInstalled(Exception):
895897

896898
# Optionally install in sys.modules for module-level mocking
897899
if install_in_sys_modules:
898-
import sys
899900
sys.modules['graphiti_providers'] = mock_providers
900901

901902
return mock_providers

‎tests/test_spec_complexity.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import json
1717
import pytest
1818
from pathlib import Path
19-
from unittest.mock import patch, AsyncMock
2019

2120
# SDK modules are pre-mocked by conftest.py before path setup
2221
# Path to apps/backend is also added by conftest.py

‎tests/test_spec_pipeline.py‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
"""
1616

1717
import json
18+
import os
1819
import pytest
1920
import time
2021
from pathlib import Path
21-
from unittest.mock import MagicMock, patch
22+
from unittest.mock import patch
2223

2324
# Import from spec.pipeline - SDK modules are pre-mocked by conftest.py
2425
from spec.pipeline import SpecOrchestrator, get_specs_dir
@@ -261,8 +262,6 @@ class TestCleanupOrphanedPendingFolders:
261262

262263
def test_removes_empty_pending_folder(self, temp_dir: Path):
263264
"""Removes empty pending folders older than 10 minutes."""
264-
import os
265-
266265
with patch('spec.pipeline.init_auto_claude_dir') as mock_init:
267266
mock_init.return_value = (temp_dir / ".auto-claude", False)
268267
specs_dir = temp_dir / ".auto-claude" / "specs"
@@ -292,8 +291,6 @@ def test_removes_empty_pending_folder(self, temp_dir: Path):
292291

293292
def test_keeps_folder_with_requirements(self, temp_dir: Path):
294293
"""Keeps pending folder with requirements.json."""
295-
import os
296-
297294
with patch('spec.pipeline.init_auto_claude_dir') as mock_init:
298295
mock_init.return_value = (temp_dir / ".auto-claude", False)
299296
specs_dir = temp_dir / ".auto-claude" / "specs"
@@ -315,8 +312,6 @@ def test_keeps_folder_with_requirements(self, temp_dir: Path):
315312

316313
def test_keeps_folder_with_spec(self, temp_dir: Path):
317314
"""Keeps pending folder with spec.md."""
318-
import os
319-
320315
with patch('spec.pipeline.init_auto_claude_dir') as mock_init:
321316
mock_init.return_value = (temp_dir / ".auto-claude", False)
322317
specs_dir = temp_dir / ".auto-claude" / "specs"

0 commit comments

Comments
 (0)