Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry#4

Open
llbbl wants to merge 1 commit into
jfpuget:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#4
llbbl wants to merge 1 commit into
jfpuget:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Sep 3, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the STFT Transformer project using Poetry as the package manager. The setup provides a ready-to-use testing environment where developers can immediately start writing and running tests.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration
  • Dependencies Migration: Analyzed existing Python files and added all required dependencies:
    • Core: pandas, numpy, librosa, soundfile, tqdm, pqdm, scikit-image, scikit-learn
    • ML/AI: torch, timm, scipy, matplotlib
  • Testing Dependencies: Added as dev dependencies:
    • pytest (main testing framework)
    • pytest-cov (coverage reporting with 80% threshold)
    • pytest-mock (mocking utilities)

Testing Configuration

  • pytest Settings: Comprehensive test discovery and execution configuration
  • Coverage Reporting: Multiple formats (HTML, XML, terminal) with proper exclusions
  • Custom Markers: unit, integration, and slow for test categorization
  • Strict Configuration: Enforces marker and config validation

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • sample_audio_data: Mock audio data for testing
  • sample_metadata_df: Sample pandas DataFrame
  • mock_config: Configuration dictionary
  • sample_paths: Directory structure setup
  • mock_numpy_array & mock_spectrogram: ML testing utilities

Additional Setup

  • .gitignore: Comprehensive Python project gitignore with testing entries
  • Validation Tests: 10 tests verifying all infrastructure components work correctly

Running Tests

Basic Commands

# Install dependencies
poetry install

# Run all tests with coverage
poetry run pytest

# Run specific test categories
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only  
poetry run pytest -m "not slow"    # Skip slow tests

# Generate coverage report
poetry run pytest --cov-report=html

Test Organization

  • Unit tests: /tests/unit/ - Fast, isolated component tests
  • Integration tests: /tests/integration/ - Cross-component interaction tests
  • Custom markers: Use @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow

Coverage Reporting

  • Threshold: 80% minimum coverage required
  • Reports: HTML (htmlcov/), XML (coverage.xml), and terminal output
  • Exclusions: Test files, cache directories, and common patterns properly excluded

Dependencies Notes

  • Python Version: Updated to ^3.9 for modern dependency compatibility
  • Missing Package: audiomentations was excluded due to version conflicts - can be added manually if needed
  • Lock File: poetry.lock created and should be committed (not in .gitignore)

Validation Results

✅ All 10 validation tests pass
✅ Coverage reporting works correctly
✅ Custom markers function properly
✅ Fixtures are available and functional
✅ Mock utilities integrated successfully

The testing infrastructure is now ready for development. Developers can immediately begin writing tests following the established patterns and conventions.

- Configure Poetry package manager with pyproject.toml
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Set up pytest configuration with coverage reporting (80% threshold)
- Create testing directory structure with unit/integration separation
- Add shared fixtures in conftest.py for common test utilities
- Configure custom pytest markers (unit, integration, slow)
- Update .gitignore with testing-related entries
- Create validation tests to verify infrastructure works correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant