RDSR
RDSR copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Set up comprehensive Python testing infrastructure
Summary
This PR establishes a complete testing infrastructure for the Real-ESRGAN project, providing developers with a robust foundation for writing and running tests.
Changes Made
Package Management
-
Configured Poetry as the package manager with a comprehensive
pyproject.toml -
Migrated dependencies from existing
requirements.txtandsetup.pyfiles - Added development dependencies: pytest, pytest-cov, pytest-mock
Testing Configuration
-
pytest configuration with custom markers (
unit,integration,slow) - Coverage reporting configured for HTML, XML, and terminal output
- 80% coverage threshold requirement
- Test discovery patterns for comprehensive test collection
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and test utilities
├── test_setup_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Testing Utilities
-
Comprehensive fixtures in
conftest.pyincluding:- Temporary directories and files
- Sample images (RGB and grayscale)
- Mock models, configs, devices, and loggers
- PyTorch tensor fixtures
- Environment variable management
- Random seed reset for reproducibility
Development Commands
-
poetry run test- Run all tests -
poetry run tests- Alternative test command - Both commands support all standard pytest options
Project Configuration
-
Updated
.gitignorewith testing artifacts, coverage reports, and development files - Coverage exclusions for non-essential directories (experiments, results, datasets)
-
Source code coverage tracking for both
realesrganandCSMmodules
Testing the Setup
Validation Tests
The setup includes comprehensive validation tests that verify:
- All testing dependencies are properly installed
- Project structure is correct
- Custom markers are configured
- Shared fixtures work correctly
- Coverage and pytest configuration is valid
Running Tests
# Install dependencies
poetry install
# Run all tests
poetry run test
# Run with specific options
poetry run test -v --no-cov
poetry run test -m "unit"
poetry run test -k "test_setup"
Dependencies Added
Core Testing Framework
-
pytest ^7.0.0- Main testing framework -
pytest-cov ^4.0.0- Coverage reporting -
pytest-mock ^3.10.0- Advanced mocking utilities
Existing Dependencies (Migrated)
-
basicsr- Basic super-resolution framework -
numpy- Numerical computing -
opencv-python- Computer vision library -
torch >=1.7- PyTorch deep learning framework -
cython- C extensions support
Configuration Details
Coverage Settings
-
Source tracking:
realesrganandCSMmodules - Exclusions: Tests, cache, virtual environments, model files
-
Reporting: HTML (
htmlcov/), XML (coverage.xml), terminal - Threshold: 80% minimum coverage required
Pytest Settings
-
Test paths:
tests/directory -
File patterns:
test_*.py,*_test.py -
Class patterns:
Test* -
Function patterns:
test_* - Strict mode: Enabled for markers and configuration
Ready for Development
The testing infrastructure is now complete and ready for use. Developers can:
-
Write unit tests in
tests/unit/ -
Write integration tests in
tests/integration/ -
Use shared fixtures from
conftest.py -
Run tests with
poetry run test - Generate coverage reports automatically
- Use custom markers to categorize tests
All validation tests pass, confirming the infrastructure is working correctly.
🤖 Generated with Claude Code