alarmBeepDetect
alarmBeepDetect copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Python Testing Infrastructure Setup
Summary
This PR establishes a complete testing infrastructure for the alarm-beep-detect Python project. The setup provides a professional development environment with proper dependency management, comprehensive testing configuration, and ready-to-use fixtures for audio-related testing.
Key Changes Made
- Package Management: Migrated from requirements.txt to Poetry with
pyproject.toml - Testing Framework: Configured pytest with coverage reporting (80% threshold)
- Directory Structure: Created organized test directories (
tests/unit/,tests/integration/) - Shared Fixtures: Added comprehensive
conftest.pywith audio testing utilities - Development Tools: Added pytest-cov, pytest-mock, and custom test markers
- Configuration: Set up proper .gitignore and pytest configuration
- Validation: Included tests to verify the infrastructure works correctly
Testing Infrastructure Components
Package Management (Poetry)
- pyproject.toml: Central configuration for dependencies, scripts, and tools
- Dependencies: Core packages (numpy) and optional audio (PyAudio) support
- Dev Dependencies: pytest, pytest-cov, pytest-mock for comprehensive testing
Test Configuration
- Coverage: 80% threshold with HTML/XML reporting in htmlcov/ and coverage.xml
- Markers: Custom markers for
unit,integration, andslowtests - Discovery: Automatic test discovery with standard naming patterns
- Output: Detailed reporting with missing coverage information
Shared Fixtures (conftest.py)
- File Operations: temp_dir, temp_file for filesystem testing
- Audio Testing: mock_pyaudio, sample_audio_data, sample_noise_data
- Configuration: mock_audio_config, mock_alarm_config for consistent test setup
- Environment: Automatic test environment setup and audio warning suppression
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_setup_validation.py # Infrastructure validation tests
├── unit/ # Fast, isolated unit tests
│ └── __init__.py
└── integration/ # Slower integration tests
└── __init__.py
Running Tests
Basic test execution:
# Run all tests
poetry run pytest
# Run with coverage
poetry run pytest --cov
# Run specific test types
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m slow # Slow tests only
Alternative commands:
poetry run test # Equivalent to pytest
poetry run tests # Alternative command
Coverage reporting:
- Terminal output with missing lines
- HTML report in
htmlcov/index.html - XML report in
coverage.xmlfor CI/CD integration
Development Notes
- PyAudio: Made optional to support environments without audio hardware
- Install with:
poetry install --extras audio - Mocked in tests for consistent behavior
- Install with:
- Python Version: Requires Python 3.9+ for numpy compatibility
- Coverage: Configured to exclude test files, build artifacts, and virtual environments
- Validation: Run
poetry run pytest tests/test_setup_validation.pyto verify setup
Next Steps
The testing infrastructure is now ready for developers to:
- Write Unit Tests: Add tests in
tests/unit/for individual functions - Add Integration Tests: Create tests in
tests/integration/for complete workflows - Use Fixtures: Leverage audio-specific fixtures for consistent test setup
- Monitor Coverage: Maintain 80% coverage threshold with detailed reporting
- Run CI/CD: Use coverage.xml and junit-xml output for automated testing
This foundation provides everything needed to maintain high code quality through comprehensive testing.