Test Infrastructure Improvement Summary¶
Objective¶
Eliminate skipped tests that were dependent on Redis/PostgreSQL by automatically provisioning test infrastructure.
Problem¶
- Before: 24 tests skipped due to missing Redis/PostgreSQL dependencies
- Tests contained
pytest.skip()calls that checked for service availability - Manual service setup required before running tests
Solution Implemented¶
1. Docker Compose Test Configuration¶
File: docker-compose.test.yml
Created a lightweight Docker Compose configuration specifically for testing: - Redis: Using redis:7-alpine with optimized settings for tests - No persistence (appendonly=no, save="") - Health checks - Exposed on port 6379
- PostgreSQL: Using
postgres:16-alpine - Test database:
fiml_test - Test user/password:
fiml_test/fiml_test_password - Health checks
- In-memory storage (tmpfs) for speed
- Exposed on port 5432
2. Pytest Configuration Updates¶
File: tests/conftest.py
Implemented automatic container lifecycle management: - Environment Setup: Set test-specific environment variables at module load time - Docker Service Fixture: - Automatically starts Redis & PostgreSQL containers before tests - Waits for services to be healthy (with timeout) - Cleans up containers after test session - Supports --no-docker flag for environments where services are already running - Settings Reload: Clears configuration cache to ensure test settings are used
3. Test Code Cleanup¶
Script: scripts/remove_test_skips.py
Automated removal of conditional skip patterns: - Removed try/except/pytest.skip() blocks from test files - Tests now expect services to be available - Updated files: - tests/test_cache.py - tests/test_integration.py - tests/test_cache_improved.py
4. Dependencies Added¶
File: pyproject.toml
Added test dependencies for container management: - psycopg2-binary>=2.9.9 - For PostgreSQL connection testing in fixtures
Results¶
Before¶
After¶
Skipped: 5 (Ray/Live system dependent - not Redis/PostgreSQL)
- 2 Ray-dependent tests (multi-agent orchestration)
- 2 Live system tests
- 1 WebSocket provider test
Passed: 260
Failed: 7 (actual test bugs, not infrastructure issues)
Impact¶
- 79% reduction in skipped tests (24 → 5)
- All 19 Redis/PostgreSQL-dependent tests now execute automatically
- Zero manual setup required for developers
- Consistent test environment across all machines
- Faster CI/CD feedback (no more "skipped due to missing service" confusion)
Usage¶
Run Tests Normally (Auto-starts containers)¶
Run Tests with Existing Services¶
Test Specific Module¶
Containersstartup Output¶
🐳 Starting test containers (Redis & PostgreSQL)...
⏳ Waiting for Redis to be ready...
✅ Redis is ready
⏳ Waiting for PostgreSQL to be ready...
✅ PostgreSQL is ready
✅ All test services are ready
Known Issues¶
L2Cache Test Failures¶
6 L2Cache tests fail because the test code expects generic set()/get() methods, but the L2Cache implementation uses domain-specific methods like set_price(), get_price(), set_fundamentals(), etc.
Not a infrastructure issue - these are test code bugs that need to be fixed separately.
Remaining Skipped Tests¶
5 tests still skipped for valid reasons: - Ray tests (2): Require Ray cluster - different infrastructure - Live system tests (2): Require external API keys/services - WebSocket provider test (1): Requires live market data providers
Future Improvements¶
- Add Ray container to docker-compose.test.yml to eliminate remaining Ray skips
- Fix L2Cache test expectations to match actual API
- Add mock providers for websocket tests
- Consider pytest-docker plugin for more advanced container management