django-testing-docs icon indicating copy to clipboard operation
django-testing-docs copied to clipboard

feat: Set up comprehensive Python testing infrastructure

Open llbbl opened this issue 5 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive Python testing infrastructure for the Django Testing Documentation project, providing developers with a ready-to-use testing environment.

Changes Made

Package Management

  • Added Poetry configuration with pyproject.toml
  • Migrated to Poetry from manual dependency management
  • Set package-mode to false since this is a documentation project (not a distributable package)

Testing Dependencies

  • pytest 7.4.0+ - Main testing framework
  • pytest-cov 4.1.0+ - Coverage reporting with HTML, XML, and terminal output
  • pytest-mock 3.11.0+ - Enhanced mocking utilities

Testing Configuration

  • Custom pytest markers: unit, integration, slow for test categorization
  • Coverage settings: 80% threshold with comprehensive reporting
  • Test discovery: Configured for test_*.py and *_test.py patterns
  • Warning filters: Configured to handle common warnings appropriately

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and test configuration
├── unit/                # Unit tests
│   └── __init__.py
├── integration/         # Integration tests
│   └── __init__.py
└── test_setup_validation.py  # Infrastructure validation tests

Shared Test Fixtures

The conftest.py includes comprehensive fixtures for:

  • File system testing: temp_dir, temp_file, project_root
  • Content testing: sample_rst_content, sample_django_test_code
  • Mocking utilities: mock_sphinx_app, mock_file_system
  • Environment management: clean_environment, configure_test_settings

Development Workflow

  • Run tests: poetry run pytest
  • Run with coverage: poetry run pytest --cov=tests --cov-report=term-missing
  • Run specific markers: poetry run pytest -m unit or poetry run pytest -m integration

Validation & Quality Assurance

  • 12 validation tests verify the infrastructure works correctly
  • 91% coverage achieved on test infrastructure code
  • All dependencies installed and verified working
  • Git configuration updated with comprehensive .gitignore

Testing Instructions

  1. Install dependencies:

    poetry install
    
  2. Run validation tests:

    poetry run pytest tests/test_setup_validation.py -v
    
  3. Run with coverage:

    poetry run pytest --cov=tests --cov-report=term-missing
    
  4. Test specific categories:

    poetry run pytest -m unit      # Unit tests only
    poetry run pytest -m slow      # Slow tests only
    

Notes

  • Poetry lock file is committed for reproducible builds
  • Coverage reports are generated in htmlcov/ directory and coverage.xml
  • Test artifacts are properly gitignored
  • Claude Code settings (.claude/) are excluded from version control
  • Documentation focus: Configuration optimized for documentation project rather than application package

The testing infrastructure is now ready for developers to write comprehensive tests for any Django testing documentation or examples that may be added to this project.

llbbl avatar Sep 01 '25 23:09 llbbl