wav2seq icon indicating copy to clipboard operation
wav2seq copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 3 months ago • 0 comments

Python Testing Infrastructure Setup

Summary

This PR establishes a complete Python testing infrastructure using Poetry as the package manager and pytest as the testing framework. The setup provides a robust foundation for test-driven development with comprehensive fixtures, coverage reporting, and organized test structure.

Changes Made

Package Management

  • ✅ Detected existing Poetry configuration in pyproject.toml
  • ✅ Added testing dependencies as development dependencies:
    • pytest ^8.0.0 - Core testing framework
    • pytest-cov ^5.0.0 - Coverage reporting
    • pytest-mock ^3.14.0 - Mocking utilities

Testing Configuration

  • ✅ Configured pytest settings in pyproject.toml:

    • Test discovery patterns for flexible test naming
    • Coverage reporting with HTML, XML, and terminal output
    • 80% coverage threshold enforcement
    • Custom test markers: unit, integration, slow
    • Strict marker enforcement and comprehensive warning filters
  • ✅ Configured coverage settings:

    • Excluded non-source directories from coverage
    • Proper handling of abstract methods and type checking blocks
    • HTML and XML report generation

Directory Structure

tests/
├── __init__.py
├── conftest.py                      # Shared fixtures
├── test_infrastructure_validation.py # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

Implemented comprehensive fixtures for common testing needs:

  • File System: temp_dir, temp_file, mock_file_system
  • Configuration: mock_config, json_file, mock_env_vars
  • Mocking: mock_logger, mock_http_response, mock_database_connection
  • Testing Utilities: benchmark_timer, sample_data, mock_async_function
  • Auto-cleanup: reset_singleton_instances (runs automatically)

Validation Tests

Created test_infrastructure_validation.py with 27 tests covering:

  • Pytest functionality verification
  • Custom marker validation
  • All fixture functionality
  • Coverage configuration
  • Project structure verification
  • pytest-mock integration

Git Configuration

  • ✅ Created comprehensive .gitignore file with:
    • Python build artifacts and cache files
    • Testing output directories
    • IDE and editor files
    • Virtual environment directories
    • Claude settings directory

How to Use

Installing Dependencies

# Install all dependencies
poetry install --no-root

# Or if you want to include the project itself
poetry install

Running Tests

# Run all tests
poetry run pytest

# Run without coverage
poetry run pytest --no-cov

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests  
poetry run pytest -m integration

# Run with specific verbosity
poetry run pytest -v  # verbose
poetry run pytest -q  # quiet

# Run specific test file
poetry run pytest tests/test_infrastructure_validation.py

# Run with coverage report
poetry run pytest --cov --cov-report=html

Writing New Tests

  1. Place unit tests in tests/unit/
  2. Place integration tests in tests/integration/
  3. Use fixtures from conftest.py for common test needs
  4. Mark tests appropriately:
    import pytest
    
    @pytest.mark.unit
    def test_my_unit_test(temp_dir, mock_logger):
        # Your test code here
        pass
    
    @pytest.mark.integration
    def test_my_integration_test(mock_database_connection):
        # Your test code here
        pass
    

Validation Results

✅ All 27 validation tests pass successfully ✅ Testing infrastructure is fully operational ✅ Coverage reporting is configured (will work once source code is added) ✅ Custom markers are functional ✅ All fixtures work as expected

Notes

  • The project uses Poetry for dependency management
  • Coverage threshold is set to 80% (will apply once source code exists)
  • The poetry.lock file is tracked in git for reproducible builds
  • Tests run in verbose mode by default with strict marker enforcement
  • The infrastructure is ready for immediate test development

llbbl avatar Aug 28 '25 15:08 llbbl