Skip to content

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

Open
llbbl wants to merge 1 commit intorakuten-nlp:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure with Poetry#1
llbbl wants to merge 1 commit intorakuten-nlp:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Aug 23, 2025

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use environment for writing and running tests with coverage reporting.

Changes Made

Package Management

  • Poetry Setup: Configured Poetry as the primary package manager via pyproject.toml
  • Dependency Migration: Migrated existing dependencies from setup.py (numpy, cython)
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • Pytest Configuration:

    • Configured test discovery patterns
    • Added coverage reporting with HTML and XML output
    • Set up custom test markers (unit, integration, slow)
    • Enabled strict mode and verbose output
  • Coverage Settings:

    • Configured source directories and exclusions
    • Set up multiple report formats (terminal, HTML, XML)
    • Excluded test files and build artifacts from coverage

Directory Structure

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

Test Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir: Temporary directory management
  • temp_file: Temporary file creation
  • mock_config: Configuration mocking
  • sample_data: Test data generation
  • mock_model: Model mocking
  • cleanup_files: File cleanup utility
  • capture_logs: Log capturing
  • benchmark_timer: Performance timing
  • mock_file_system: File system mocking

Additional Setup

  • Updated .gitignore with testing artifacts and common Python excludes
  • Created validation tests to verify the infrastructure works correctly
  • Configured Poetry scripts for running tests (poetry run test and poetry run tests)

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests with coverage
poetry run test

# Alternative command
poetry run tests

# Run specific test markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

# Run with specific options
poetry run pytest -v --cov-report=html

Writing 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 with @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow

Coverage Reports

  • Terminal: Displayed after each test run
  • HTML: Generated in htmlcov/ directory
  • XML: Generated as coverage.xml for CI/CD integration

Notes

  • Coverage threshold is currently set to 0% to allow initial setup without existing tests
  • Developers should adjust the threshold in pyproject.toml as tests are added
  • The validation test suite (test_infrastructure_validation.py) verifies all components work correctly
  • All Cython extensions (.pyx files) are excluded from coverage reporting

- Add Poetry package manager configuration in pyproject.toml
- Configure pytest with coverage reporting and custom markers
- Create test directory structure with unit/integration separation
- Add comprehensive test fixtures in conftest.py
- Update .gitignore with testing and build artifacts
- Include validation tests to verify infrastructure setup
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