Files
NexQuant/pytest.ini
T
TPTBusiness c36d27790b test: Add backtesting tests with 98.77% coverage
New test infrastructure:

1. pytest + pytest-cov installed
   - requirements.txt updated
   - pytest.ini configured
   - .coveragerc for coverage

2. Test suite created (97 tests):
   - test_backtest_engine.py (32 tests)
     * BacktestMetrics: IC, Sharpe, Drawdown, Win Rate
     * FactorBacktester: run_backtest, JSON export
     * Edge cases: NaN, empty, insufficient data

   - test_results_db.py (33 tests)
     * ResultsDatabase: CRUD operations
     * Queries: get_top_factors, get_aggregate_stats
     * Database cleanup

   - test_risk_management.py (32 tests)
     * CorrelationAnalyzer: Matrix, uncorrelated factors
     * PortfolioOptimizer: Mean-Variance, Risk Parity
     * AdvancedRiskManager: Limit checks

3. Fixtures (conftest.py):
   - 22 reusable test fixtures
   - Mock data for all scenarios
   - Sample factors, returns, equity curves

4. Coverage: 98.77% (target: >80%)
   - BacktestMetrics: 100%
   - FactorBacktester: 100%
   - ResultsDatabase: 95.92%
   - CorrelationAnalyzer: 100%
   - PortfolioOptimizer: 100%
   - AdvancedRiskManager: 100%

5. Documentation:
   - test/backtesting/README.md
   - How to run tests
   - Generate coverage reports

Run tests:
  pytest test/backtesting/ -v

Coverage report:
  pytest test/backtesting/ --cov=rdagent/components/backtesting --cov-report=html
2026-04-02 19:24:38 +02:00

32 lines
652 B
INI

[pytest]
# Test discovery
testpaths = test
python_files = test_*.py
python_classes = Test*
python_functions = test_*
# Coverage settings
addopts =
--cov=rdagent/components/backtesting
--cov-report=term-missing
--cov-report=html:htmlcov
--cov-report=xml:coverage.xml
--cov-fail-under=80
-v
--tb=short
# Filter warnings
filterwarnings =
ignore::DeprecationWarning
ignore::PendingDeprecationWarning
# Logging
log_cli = false
log_cli_level = INFO
# Markers
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
integration: marks tests as integration tests
unit: marks tests as unit tests