msdat
msdat copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the MSDAT project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with coverage reporting.
Changes Made
Package Management
- Poetry Setup: Added
pyproject.tomlwith Poetry configuration - Dependency Migration: Migrated all dependencies from
requirements.txtto Poetry - Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
-
pytest Configuration:
- Configured test discovery patterns
- Added custom markers (unit, integration, slow)
- Set up coverage reporting with HTML and XML outputs
- Enabled strict markers and configuration
-
Coverage Configuration:
- Source directory coverage tracking
- Excluded test files, cache directories, and virtual environments
- Configured coverage report formats and exclusion patterns
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir- Temporary directory managementtemp_file- Temporary file creationmock_config- Mock configuration dictionarymock_database_connection- Mock database connection and cursormock_argparse_args- Mock command line argumentsmock_logger- Mock logger objectsample_sql_results- Sample SQL query resultsmock_file_system- Mock file system structuremock_network_response- Mock network responsesreset_modules- Module reset between testscapture_output- Stdout/stderr capturemock_progressbar- Mock progress barenvironment_variables- Temporary environment variable managementmock_color_output- Mock colored terminal output
Other Updates
- gitignore: Updated with testing artifacts (.pytest_cache/, coverage files) and Claude settings
- Poetry Scripts: Added
poetry run testandpoetry run testscommands
How to Use
-
Install dependencies:
poetry install -
Run all tests:
poetry run test # or poetry run tests -
Run specific test files:
poetry run pytest tests/test_setup_validation.py -
Run tests with specific markers:
poetry run pytest -m unit # Run only unit tests poetry run pytest -m integration # Run only integration tests poetry run pytest -m "not slow" # Skip slow tests -
View coverage report:
- HTML report: Open
htmlcov/index.htmlin a browser - XML report: Available at
coverage.xml
- HTML report: Open
Notes
- The testing infrastructure is ready to use - developers can immediately start writing tests
- Coverage threshold is currently not enforced to allow gradual test adoption
- The argparse package was removed from dependencies as it conflicts with pytest (argparse is built-in to Python 3)
- All pytest options are available when using the poetry run test/tests commands
Validation
The setup has been validated with a comprehensive test file (test_setup_validation.py) that verifies:
- All testing dependencies are properly installed
- All fixtures are working correctly
- Test markers are configured
- Coverage reporting is functional