Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 17, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the media toolkit API project, migrating from traditional pip/requirements.txt to Poetry for modern dependency management and adding pytest as the testing framework.

Changes Made

Package Management

  • ✅ Migrated from requirements.txt to Poetry package manager
  • ✅ Created pyproject.toml with all existing dependencies
  • ✅ Added package-mode = false since this is an application, not a library
  • ✅ Generated poetry.lock file for reproducible builds

Testing Dependencies

Added as development dependencies:

  • pytest (v7.4.0) - Main testing framework
  • pytest-cov (v4.1.0) - Coverage reporting plugin
  • pytest-mock (v3.11.0) - Mocking utilities

Testing Configuration

Configured in pyproject.toml:

  • pytest settings:
    • Test discovery patterns for test_*.py and *_test.py
    • Strict markers and configuration
    • Coverage reporting with HTML and XML outputs
    • 80% coverage threshold (currently disabled for initial setup)
    • Custom markers: unit, integration, slow
  • coverage settings:
    • Comprehensive exclusion patterns
    • HTML and XML report generation
    • Detailed reporting configuration

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)

Created comprehensive fixtures for common testing needs:

  • temp_dir - Temporary directory management
  • temp_file - Temporary file creation
  • mock_config - Mock application configuration
  • mock_flask_app - Mock Flask application
  • mock_request - Mock Flask request object
  • sample_media_files - Sample files for testing
  • mock_subprocess - Mock for command-line tools
  • mock_cloud_storage - Mock for GCS/S3 clients
  • mock_whisper_model - Mock for transcription testing
  • env_vars - Environment variable management
  • cleanup_test_files - Automatic test file cleanup
  • mock_http_response - Mock HTTP responses

Additional Updates

  • Enhanced .gitignore with:
    • Testing artifacts (.pytest_cache/, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • Python build artifacts and virtual environments
    • IDE files and temporary files

Running Tests

Install dependencies

poetry install

Run all tests

poetry run pytest

Run with coverage

poetry run pytest --cov

Run specific test 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

Run validation tests

poetry run pytest tests/test_setup_validation.py -v

Notes

  1. Coverage Threshold: The 80% coverage requirement is configured but may need adjustment based on project needs. Currently, running tests on the entire codebase shows 0% coverage since no actual unit tests exist yet.

  2. Poetry Lock File: The poetry.lock file has been generated and should be committed to ensure reproducible builds across environments.

  3. Validation Tests: Created test_setup_validation.py to verify the testing infrastructure is properly configured. All 10 validation tests pass successfully.

  4. Next Steps:

    • Developers can now start writing unit tests in tests/unit/
    • Integration tests can be added to tests/integration/
    • Coverage will automatically be tracked and reported

Testing the Setup

The infrastructure has been validated with a test run showing:

  • ✅ All testing dependencies installed correctly
  • ✅ Test discovery working properly
  • ✅ Custom markers configured
  • ✅ Fixtures available and functional
  • ✅ Coverage reporting generates HTML and XML reports

This provides a solid foundation for comprehensive test coverage of the media toolkit API.

- Migrate from requirements.txt to Poetry for dependency management
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure comprehensive pytest and coverage settings in pyproject.toml
- Create proper testing directory structure (tests/unit, tests/integration)
- Add shared fixtures in conftest.py for common testing needs
- Update .gitignore with testing artifacts and Claude settings
- Add validation tests to verify infrastructure setup
@HarrisonFisher HarrisonFisher changed the base branch from main to build June 17, 2025 23:00
@stephengpope
Copy link
Owner

this is pretty cool, do you have a demo of this working? @llbbl

@llbbl
Copy link
Author

llbbl commented Jun 30, 2025

Hello @stephengpope, I’m trying to get unit testing going for as many public projects as possible. The first PR is to set up testing. Additional PRs to be added as a follow-up with actual tests. I’m tracking what PRs get merged.

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.

2 participants