Skip to content

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

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

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

Conversation

@llbbl

@llbbl llbbl commented Jun 24, 2025

Copy link
Copy Markdown

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the FilmAgent Python project using Poetry for dependency management and pytest for testing.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependencies: Migrated all identified dependencies from code analysis:
    • Production: python-Levenshtein, openai, requests, tqdm, fastapi, uvicorn, torch, soundfile
    • Development: pytest, pytest-cov, pytest-mock

Testing Configuration

  • Pytest Configuration:
    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with 80% threshold
    • HTML and XML coverage reports
    • Custom markers: unit, integration, slow
  • Coverage Settings:
    • Source directories: FilmAgent and TTS
    • Exclusions for test files, cache, and virtual environments

Project Structure

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

Testing Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory management
  • mock_config: Mock configuration for testing
  • sample_character_profiles: Test data for character profiles
  • sample_scene: Test scene structure
  • mock_file_system: Mock file system setup
  • mock_llm_response: Mock LLM API responses
  • mock_openai_client: Mock OpenAI client
  • And many more...

Additional Setup

  • .gitignore: Comprehensive Python gitignore including:
    • Python artifacts (__pycache__, *.pyc, etc.)
    • Testing artifacts (.coverage, htmlcov/, etc.)
    • IDE files (.vscode/, .idea/)
    • Project-specific files (logs, models, audio files)
    • Claude settings (.claude/*)
  • __init__.py files: Added to make FilmAgent and TTS proper Python packages

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test         # or
    poetry run tests        # both commands work
  3. Run tests with options:

    poetry run pytest -v                    # verbose output
    poetry run pytest -m unit               # only unit tests
    poetry run pytest -m "not slow"         # exclude slow tests
    poetry run pytest --cov-report=html     # generate HTML coverage report
  4. View coverage report:

    • Terminal: Automatically shown after test run
    • HTML: Open htmlcov/index.html in browser
    • XML: Available at coverage.xml for CI integration

Notes

  • The infrastructure is ready for developers to start writing tests
  • Coverage threshold is set to 80% but currently shows 0% as no actual code tests exist yet
  • All validation tests pass, confirming the infrastructure works correctly
  • Both poetry run test and poetry run tests commands are available as requested

- Add Poetry for dependency management with pyproject.toml configuration
- Configure pytest with coverage reporting (80% threshold)
- Set up testing directory structure (tests/unit, tests/integration)
- Add comprehensive pytest fixtures in conftest.py
- Configure test discovery patterns and custom markers
- Create validation tests to verify infrastructure works
- Update .gitignore with testing and Python-specific entries
- Add poetry script commands for running tests
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