SharPyShell
SharPyShell copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure with Poetry
Summary
This PR introduces a comprehensive testing infrastructure for the SharPyShell project using Poetry as the package manager and pytest as the testing framework. The setup provides a modern, maintainable foundation for writing and running tests with coverage reporting.
Changes Made
Package Management
- Poetry Setup: Migrated from
requirements.txtto Poetry withpyproject.toml - Dependency Management: All existing dependencies preserved and properly categorized
- Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
-
pytest Configuration:
- Configured test discovery patterns
- Set up coverage reporting with 80% threshold
- Added custom markers for unit, integration, and slow tests
- Configured output formatting and strict options
-
Coverage Settings:
- Source directories:
core/,modules/,utils/ - Multiple report formats: terminal, HTML, and XML
- Excluded test files and
__init__.pyfrom coverage
- Source directories:
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_infrastructure_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir: Temporary directory for test filesmock_config: Mock configuration objectsample_data: Common test datamock_file_system: Mock file system structuremock_network: Network operation mocksmock_subprocess: Subprocess call mocksreset_environment: Environment variable resetcapture_logs: Log capture for testingmock_crypto: Cryptographic operation mocks
Running Tests
To run tests using Poetry:
# Install dependencies (first time only)
poetry install
# Run all tests
poetry run test
# or
poetry run tests
# Run tests with specific options
poetry run pytest -v # Verbose output
poetry run pytest tests/unit/ # Run only unit tests
poetry run pytest -m integration # Run only integration tests
poetry run pytest --no-cov # Run without coverage
Coverage Reports
After running tests, coverage reports are available in:
- Terminal: Displayed automatically with missing lines
- HTML:
htmlcov/index.html- Interactive HTML report - XML:
coverage.xml- For CI/CD integration
Notes
- The 80% coverage threshold is configured but won't block tests initially since no source code tests exist yet
- Poetry lock file (
poetry.lock) is committed for reproducible builds - All pytest standard options are available through the Poetry scripts
- The validation tests confirm that the infrastructure is working correctly
Next Steps
With this infrastructure in place, developers can now:
- Write unit tests in
tests/unit/ - Write integration tests in
tests/integration/ - Use the provided fixtures for common testing scenarios
- Run tests with coverage to ensure code quality