Test suite hangs due to config loading before test environment setup
Author: career091101Created Aug 11, 2025Updated Sep 17, 2026
Bug Description
The test suite hangs or times out when running unit tests due to a configuration loading issue.
Root Cause
The tradingagents/config.py file calls get_config() at module import time (line 68), which validates API keys. However, the test fixture in tests/conftest.py sets test environment variables (lines 11-14) but imports DEFAULT_CONFIG afterwards (line 16). This creates a race condition where:
- When pytest imports the test files, it loads conftest.py
- conftest.py sets test environment variables
- conftest.py then imports DEFAULT_CONFIG from tradingagents.default_config
- This triggers the import of tradingagents.config, which immediately calls get_config()
- The validation may fail or hang waiting for API keys
Impact
- Unit tests cannot run properly
- CI/CD pipeline failures
- Development workflow blocked
Solution
The config module should not eagerly load configuration at import time. Instead, it should use lazy loading or allow tests to override the configuration before validation occurs.
Steps to Reproduce
- Run
python -m pytest tests/unit/ - Tests will hang or timeout
Environment
- Python 3.13
- pytest
- TradingAgents framework
Source: TauricResearch/TradingAgents