Skip to content

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

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

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

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Aug 22, 2025

Python Testing Infrastructure Setup

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 where developers can immediately start writing unit and integration tests.

Changes Made

Package Management

  • Poetry Configuration: Set up Poetry as the primary package manager
  • Dependency Migration: Migrated all existing dependencies from requirements.txt to pyproject.toml
  • Removed argparse: Removed the redundant argparse package (built into Python)

Testing Framework

  • pytest: Added as the main testing framework (v7.4.0)
  • pytest-cov: Added for coverage reporting (v4.1.0)
  • pytest-mock: Added for mocking utilities (v3.11.0)
  • Development Tools: Added black, isort, flake8, and mypy for code quality

Configuration (pyproject.toml)

  • pytest Settings:

    • Configured test discovery patterns
    • Set up strict markers (unit, integration, slow)
    • Configured verbose output with local variables
    • Added comprehensive error filtering
  • Coverage Settings:

    • 80% coverage threshold requirement
    • HTML, XML, and terminal reporting
    • Proper source directory configuration
    • Exclusion patterns for test files and virtual environments

Directory Structure

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

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing patterns:

  • temp_dir and temp_file: Temporary file/directory management
  • mock_config: Mock configuration dictionary
  • mock_api_response: Mock API response data
  • mock_database_connection: Mock database operations
  • mock_http_client: Mock HTTP client for API testing
  • sample_json_file: Sample JSON data for testing
  • mock_logger: Mock logging functionality
  • environment_variables: Test environment variable management
  • mock_celery_task: Mock Celery task operations
  • mock_flask_app: Mock Flask application
  • capture_logs: Log capture for testing

Validation Tests

Created comprehensive validation tests to verify:

  • All fixtures work correctly
  • Test markers are registered
  • Directory structure is correct
  • Configuration is properly set up
  • Coverage reporting functions

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests
poetry run test

# Alternative command
poetry run tests

# Run with specific options
poetry run pytest tests/ -v

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

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

# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

Coverage Reports

  • Terminal: Automatically shown when running tests
  • HTML Report: Generated in htmlcov/ directory
  • XML Report: Generated as coverage.xml for CI/CD integration

Notes

  • The coverage threshold is set to 80% and will fail the test run if not met
  • For the validation tests, coverage can be bypassed with --no-cov flag
  • All test dependencies are in the test group and won't be installed in production
  • The infrastructure is ready for immediate test development

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing patterns
  4. Run tests with coverage to ensure code quality

- Configured Poetry as package manager with all existing dependencies
- Added pytest, pytest-cov, and pytest-mock for testing framework
- Created complete test directory structure with unit/integration subdirs
- Configured pytest with coverage, markers, and strict settings (80% threshold)
- Added comprehensive shared fixtures in conftest.py for common testing patterns
- Updated .gitignore with testing artifacts and Claude settings
- Created validation tests to verify infrastructure works correctly
- Set up Poetry scripts for running tests via 'poetry run test/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