Skip to content

feat: Set up comprehensive Python testing infrastructure - #2

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

llbbl wants to merge 1 commit into
vaibs-d:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 3, 2025

Copy link
Copy Markdown

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the QR Redactor Python project, migrating from a simple requirements.txt setup to a modern Poetry-based development environment with full testing capabilities.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry format
  • Test Dependencies: Added pytest, pytest-cov, pytest-mock, and pytest-asyncio

Testing Configuration

  • Pytest Configuration: Comprehensive pytest settings in pyproject.toml

    • Custom markers: unit, integration, slow
    • Coverage reporting with 80% threshold
    • HTML and XML coverage output formats
    • Strict mode and enhanced output options
  • Coverage Configuration: Detailed coverage settings

    • Source directory inclusion/exclusion rules
    • Multiple output formats (terminal, HTML, XML)
    • Skip lines for common non-testable code patterns

Directory Structure

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

Shared Test Fixtures

The conftest.py file provides comprehensive fixtures including:

  • temp_dir and temp_file for file system testing
  • sample_text and sample_sensitive_data for application-specific testing
  • test_client for FastAPI endpoint testing
  • test_db for isolated database testing
  • mock_* fixtures for various mocking scenarios
  • Environment variable mocking support

Development Workflow

  • Testing Commands:

    • poetry run pytest - Run all tests
    • 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
  • Coverage Reporting:

    • Terminal output with missing lines
    • HTML reports in htmlcov/ directory
    • XML reports for CI integration

Project Configuration

  • Updated .gitignore: Added testing artifacts, coverage reports, and Claude settings
  • Lock File Management: Poetry.lock properly tracked (not gitignored)

Validation

The infrastructure has been validated with a comprehensive test suite (test_infrastructure.py) that verifies:

  • ✅ Pytest functionality and custom markers
  • ✅ Fixture availability and functionality
  • ✅ Mocking capabilities
  • ✅ FastAPI test client integration
  • ✅ Database fixture setup
  • ✅ Async test support
  • ✅ Project structure integrity
  • ✅ Coverage configuration

Testing Instructions

Install Dependencies

cd qr-redactor
poetry install

Run All Tests

poetry run pytest

Run Tests with Coverage

poetry run pytest --cov=app --cov-report=html

Run Specific Test Types

# Unit tests only
poetry run pytest -m unit

# Integration tests only  
poetry run pytest -m integration

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

View Coverage Report

After running tests with coverage, open htmlcov/index.html in your browser.

Notes

  • Poetry Lock File: The poetry.lock file is intentionally tracked in git for reproducible builds
  • Coverage Threshold: Set to 80% - tests will fail if coverage drops below this threshold
  • Test Database: Uses isolated SQLite database for testing that's automatically cleaned up
  • FastAPI Integration: Full test client setup for API endpoint testing
  • Async Support: Configured for testing async FastAPI endpoints

Ready for Development

The testing infrastructure is now ready for developers to start writing:

  • Unit tests in tests/unit/
  • Integration tests in tests/integration/
  • All shared fixtures are available via conftest.py
  • Coverage reporting will track test effectiveness
  • CI/CD integration ready with XML coverage reports

- Add Poetry package manager with pyproject.toml configuration
- Migrate dependencies from requirements.txt to Poetry format
- Add pytest, pytest-cov, pytest-mock, and pytest-asyncio as test dependencies
- Configure pytest with custom markers (unit, integration, slow)
- Set up coverage reporting with 80% threshold, HTML and XML output
- Create tests/ directory structure with unit/ and integration/ subdirectories
- Add comprehensive conftest.py with shared fixtures for testing
- Update .gitignore with testing-related entries and Claude configuration
- Create validation test suite to verify infrastructure functionality
- All tests passing with proper coverage reporting and marker filtering
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