fix: resolve circular import in integration tests#19
Conversation
Move imports inside test function to delay until execution time, avoiding circular import during pytest collection. Root cause: After make sync installs the package, entry points are registered. When celeste is imported, _load_from_entry_points() calls register_package(), which imports client.py while io.py is still initializing, causing a circular import. Solution: Move TextGenerationOutput, TextGenerationUsage, and TextGenerationParameters imports from module level to inside the test function. This delays imports until test execution (after pytest collection), avoiding the circular import.
PR Review: Fix Circular Import in Integration TestsSummaryThis PR successfully addresses a circular import issue that was preventing integration tests from running after ✅ Strengths
🔍 Code Quality ObservationsFile: tests/integration_tests/test_text_generation/test_generate.py:20-27 The fix is sound, but here are some considerations: Minor: Import Style InconsistencyThe codebase follows a pattern of module-level imports (seen in all unit tests like Suggestion: Consider if this signals a deeper architectural issue with the entry point loading mechanism (see Architecture Considerations below). Type Annotation ChangeChanging from (Provider.GOOGLE, "gemini-2.5-flash-lite", {"thinking_budget": 0}),However, this loses some type safety. You could consider: from typing import Any
parameters: dict[str, Any]🏗️ Architecture ConsiderationsWhile this fix works, it treats a symptom rather than the root cause. Consider these longer-term improvements: 1. Entry Point Loading StrategyThe circular import stems from Potential alternatives:
2. Test IsolationIntegration tests shouldn't be affected by package installation state. Consider:
3. Import Structure in celeste_text_generationThe 🐛 Potential IssuesNone identified - The fix is safe and doesn't introduce bugs. The only edge case: If other tests are added that import 🔒 Security ConcernsNone - This is a test-only change with no security implications. 🧪 Test CoverageCurrent state: ✅ Good
Recommendations for follow-up:
📝 Style & ConventionsWithout access to ✅ Follows Python standards:
🎯 RecommendationsImmediate (for this PR):
Follow-up (future work):
📊 Final AssessmentCode Quality: ⭐⭐⭐⭐ (4/5) - Clean fix with good documentation Overall: ✅ Approve - This is a well-executed fix for a blocking issue. The approach is pragmatic and properly documented. Recommended for merge with optional follow-up to address architectural concerns. Great work on the thorough root cause analysis! 🎉 |
Problem
Integration tests were failing with a circular import error after
make syncinstalled thetext-generationpackage:Root Cause
After
make syncinstalls the package, entry points are registered. When pytest collects tests:from celeste_text_generation import TextGenerationOutputceleste_text_generation/__init__.py→ importsio.pyio.pyimportsceleste.io→celeste/__init__.pycalls_load_from_entry_points()register_package()importsclient.pywhileio.pyis still initializingSolution
Move imports from module level to inside the test function. This delays imports until test execution (after pytest collection), avoiding the circular import.
Changes
TextGenerationOutput,TextGenerationUsage, andTextGenerationParametersimports insidetest_generate()functioncelesteimports at module level (they don't trigger the circular import)Testing
--collect-only)Fixes CI integration-test job failure.