Skip to content

feat: Add complete Python testing infrastructure with Poetry#518

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

feat: Add complete Python testing infrastructure with Poetry#518
llbbl wants to merge 1 commit intomlbvn:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 27, 2025

Add Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the Machine Learning Yearning translation project. It introduces Poetry as the package manager and sets up pytest with comprehensive configuration for unit and integration testing.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry setup, migrating from Dockerfile dependencies
  • Dependency Management:
    • Production: pdfkit (^1.0.0), grip (4.5.2)
    • Development: pytest (^7.4.3), pytest-cov (^4.1.0), pytest-mock (^3.12.0)

Testing Setup

  • Directory Structure:

    tests/
    ├── __init__.py
    ├── conftest.py           # Shared fixtures
    ├── test_setup_validation.py
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    
  • Pytest Configuration:

    • Test discovery patterns configured
    • Coverage reporting with 80% threshold
    • Output formats: terminal, HTML, XML
    • Custom markers: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow
  • Shared Fixtures (in conftest.py):

    • temp_dir: Temporary directory management
    • sample_markdown_content: Test markdown content
    • sample_chapter_file: Mock chapter files
    • mock_chapters_dir: Mock chapters directory
    • mock_imgs_dir: Mock images directory
    • mock_project_structure: Complete mock project
    • env_vars: Test environment variables
    • mock_pdf_config: PDF configuration
    • cleanup_test_files: Automatic test file cleanup

Additional Updates

  • .gitignore: Added comprehensive entries for:
    • Python artifacts and caches
    • Testing outputs (.pytest_cache/, coverage files)
    • Virtual environments
    • IDE files
    • Claude-specific directories
    • Project-specific generated files

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest
# or
poetry run test
# or
poetry run tests

Run Specific Test Types

# Unit tests only
poetry run pytest -m unit

# Integration tests only
poetry run pytest -m integration

# Exclude slow tests
poetry run pytest -m "not slow"

Coverage Reports

  • Terminal: Shown by default when running tests
  • HTML Report: Available at htmlcov/index.html
  • XML Report: Generated as coverage.xml

Notes

  • The project is configured as a script project (not a package) with package-mode = false
  • Coverage threshold is set to 80% - tests will fail if coverage drops below this
  • The validation test suite confirms all infrastructure components are working correctly
  • Poetry lock file should be committed to ensure reproducible builds

- Set up Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create test directory structure with unit/integration folders
- Add comprehensive shared fixtures in conftest.py
- Update .gitignore with testing and Claude-related entries
- Add validation tests to verify infrastructure setup
- Configure custom test markers (unit, integration, slow)
- Set up Poetry scripts 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