cuc-ns
cuc-ns copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
Set up Python Testing Infrastructure with Poetry
Summary
This PR establishes a comprehensive testing infrastructure for the project using Poetry as the package manager. The setup provides developers with a complete, ready-to-use testing environment that follows Python best practices.
Changes Made
Package Management
-
Added
pyproject.tomlwith Poetry configuration - Configured dependencies: numpy, matplotlib, scikit-learn, scipy for existing ROC curve demo
- Added testing dependencies: pytest, pytest-cov, pytest-mock
Testing Configuration
-
pytest configuration in
pyproject.tomlwith:- 80% coverage threshold requirement
- HTML and XML coverage reporting
- Custom markers:
unit,integration,slow - Strict configuration and test discovery patterns
- Coverage configuration with appropriate source paths and exclusions
Directory Structure
-
Created testing directories:
tests/,tests/unit/,tests/integration/ -
Added
__init__.pyfiles for proper Python package structure -
Comprehensive
conftest.pywith shared fixtures including:- Temporary file/directory management
- Mock configurations and data
- Numpy random seed control
- Matplotlib non-interactive backend setup
- Parametrized fixtures for boolean/numeric testing
Development Environment
-
Updated
.gitignorewith Python, testing, virtual environment, and IDE entries - Preserved lock file tracking (poetry.lock not ignored as per best practices)
- Infrastructure validation tests to verify setup works correctly
Running Tests
Basic Commands
# Run all tests with coverage
poetry run pytest
# Run tests without coverage
poetry run pytest --no-cov
# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow
# Run with verbose output
poetry run pytest -v
Coverage Reports
- Terminal: Coverage summary shown after each test run
-
HTML:
htmlcov/index.html(detailed interactive report) -
XML:
coverage.xml(CI/CD integration)
Validation
The setup includes comprehensive validation tests (tests/test_infrastructure.py) that verify:
- ✅ Python version compatibility (3.8+)
- ✅ All required packages import correctly
- ✅ Shared fixtures function properly
- ✅ Testing markers work as expected
- ✅ Project structure is correct
- ✅ Matplotlib uses non-interactive backend
- ✅ Coverage configuration is valid
All validation tests pass successfully, confirming the testing infrastructure is ready for use.
Next Steps
Developers can now:
-
Install dependencies:
poetry install -
Write unit tests in
tests/unit/ -
Write integration tests in
tests/integration/ -
Use shared fixtures from
conftest.py -
Run tests with coverage using
poetry run pytest
The infrastructure is designed to support immediate test development for the existing ROC curve demo (ds-security/attach/py/roc.py) and any future Python components.