feat: Implement code review improvements from gemini-2.5-pro analysis
✨ Key improvements: • Added public reset_for_testing() method to registry for clean test state management • Updated test setup/teardown to use new public API instead of private attributes • Enhanced inject_transport helper to ensure OpenAI provider registration • Migrated additional test files to use inject_transport pattern • Reduced code duplication by ~30 lines across test files 🔧 Technical details: • transport_helpers.py: Always register OpenAI provider for transport tests • test_o3_pro_output_text_fix.py: Use reset_for_testing() API, remove redundant registration • test_o3_pro_fixture_bisect.py: Migrate all 4 test methods to inject_transport • test_o3_pro_simplified.py: Migrate both test methods to inject_transport • providers/registry.py: Add reset_for_testing() public method ✅ Quality assurance: • All 7 o3-pro tests pass with new helper pattern • No regression in test isolation or provider state management • Improved maintainability through centralized transport injection • Follows single responsibility principle with focused helper function 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -17,8 +17,6 @@ import pytest
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from providers import ModelProviderRegistry
|
||||
from providers.base import ProviderType
|
||||
from providers.openai_provider import OpenAIModelProvider
|
||||
from tests.transport_helpers import inject_transport
|
||||
from tools.chat import ChatTool
|
||||
|
||||
@@ -35,32 +33,20 @@ class TestO3ProOutputTextFix:
|
||||
"""Test o3-pro response parsing fix using respx for HTTP recording/replay."""
|
||||
|
||||
def setup_method(self):
|
||||
"""Set up the test by ensuring OpenAI provider is registered."""
|
||||
# Clear any cached providers to ensure clean state
|
||||
ModelProviderRegistry.clear_cache()
|
||||
# Reset the entire registry to ensure clean state
|
||||
ModelProviderRegistry._instance = None
|
||||
# Clear both class and instance level attributes
|
||||
if hasattr(ModelProviderRegistry, "_providers"):
|
||||
ModelProviderRegistry._providers = {}
|
||||
# Get the instance and clear its providers
|
||||
instance = ModelProviderRegistry()
|
||||
instance._providers = {}
|
||||
instance._initialized_providers = {}
|
||||
# Manually register the OpenAI provider to ensure it's available
|
||||
ModelProviderRegistry.register_provider(ProviderType.OPENAI, OpenAIModelProvider)
|
||||
"""Set up the test by ensuring clean registry state."""
|
||||
# Use the new public API for registry cleanup
|
||||
ModelProviderRegistry.reset_for_testing()
|
||||
# Provider registration is now handled by inject_transport helper
|
||||
|
||||
def teardown_method(self):
|
||||
"""Clean up after test to ensure no state pollution."""
|
||||
# Clear registry to prevent affecting other tests
|
||||
ModelProviderRegistry.clear_cache()
|
||||
ModelProviderRegistry._instance = None
|
||||
ModelProviderRegistry._providers = {}
|
||||
# Use the new public API for registry cleanup
|
||||
ModelProviderRegistry.reset_for_testing()
|
||||
|
||||
@pytest.mark.no_mock_provider # Disable provider mocking for this test
|
||||
async def test_o3_pro_uses_output_text_field(self, monkeypatch):
|
||||
"""Test that o3-pro parsing uses the output_text convenience field via ChatTool."""
|
||||
# Set API key inline - helper will handle provider registration
|
||||
# Set API key inline - helper will handle provider registration
|
||||
monkeypatch.setenv("OPENAI_API_KEY", "dummy-key-for-replay")
|
||||
|
||||
cassette_path = cassette_dir / "o3_pro_basic_math.json"
|
||||
|
||||
Reference in New Issue
Block a user