Skip to content

feat: Set up comprehensive Python testing infrastructure#3

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

feat: Set up comprehensive Python testing infrastructure#3
llbbl wants to merge 1 commit intokzar:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 1, 2025

Set up comprehensive Python testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the davemail Python project, providing developers with a ready-to-use environment for writing and running tests.

Changes Made

Package Management

  • Poetry Configuration: Set up pyproject.toml with Poetry as the package manager
  • Dependency Management: Migrated existing dependencies (configobj, notmuch) and added testing dependencies
  • Development Dependencies: Added pytest (7.4.0+), pytest-cov (4.1.0+), and pytest-mock (3.11.0+)

Testing Configuration

  • Pytest Settings: Configured comprehensive pytest options in pyproject.toml including:
    • Test discovery patterns for various file naming conventions
    • Strict configuration and markers enforcement
    • Verbose output formatting
  • Custom Markers: Added three test markers for categorization:
    • @pytest.mark.unit - Unit tests
    • @pytest.mark.integration - Integration tests
    • @pytest.mark.slow - Slow-running tests
  • Coverage Configuration: Set up coverage reporting with:
    • 80% coverage threshold requirement
    • HTML reports (htmlcov/ directory)
    • XML reports (coverage.xml file)
    • Exclusion of test files and virtual environments

Directory Structure

  • Testing Directories: Created organized test structure:
    tests/
    ├── __init__.py
    ├── conftest.py
    ├── unit/
    │   └── __init__.py
    ├── integration/
    │   └── __init__.py
    └── test_infrastructure_validation.py
    

Testing Fixtures & Utilities

  • Shared Fixtures: Comprehensive conftest.py with fixtures for:
    • Temporary directories and files
    • Mock configuration objects (ConfigObj)
    • Mock notmuch database and email objects
    • Mock subprocess calls
    • Sample email content for testing
    • Environment cleanup utilities

Project Configuration

  • Updated .gitignore: Added comprehensive exclusions for:
    • Testing artifacts (.pytest_cache/, htmlcov/, coverage.xml)
    • Virtual environments (.venv/, .env)
    • IDE files (.vscode/, .idea/)
    • Build artifacts (dist/, *.egg-info/)
    • Claude Code settings (.claude/*)

Validation

  • Infrastructure Tests: Created validation test suite to verify:
    • Python version compatibility (3.8+)
    • Project structure correctness
    • Pytest configuration accessibility
    • Fixture availability and functionality
    • Coverage configuration
    • Custom marker functionality

How to Run Tests

Basic Test Commands

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run tests with coverage
poetry run pytest --cov

# Run without coverage (for development)
poetry run pytest --no-cov

# Run specific test categories
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only
poetry run pytest -m slow          # Slow tests only

Coverage Reports

# Generate HTML coverage report
poetry run pytest --cov --cov-report=html

# View coverage report
open htmlcov/index.html  # macOS
xdg-open htmlcov/index.html  # Linux

Test Discovery

Pytest will automatically discover tests following these patterns:

  • Files: test_*.py, *_test.py
  • Classes: Test*
  • Functions: test_*

Dependencies Added

Production Dependencies

  • configobj ^5.0 - Configuration file parsing
  • notmuch * - Email indexing and search

Development Dependencies

  • pytest ^7.4.0 - Testing framework
  • pytest-cov ^4.1.0 - Coverage reporting
  • pytest-mock ^3.11.0 - Mocking utilities

Notes

  • Coverage Threshold: Set to 80% - tests will fail if coverage drops below this threshold
  • Lock File: poetry.lock is tracked in git for reproducible builds
  • Python Version: Configured for Python 3.8+ compatibility
  • Ready for Development: Infrastructure is complete - developers can immediately start writing tests

The testing infrastructure is now fully functional and ready for use. All validation tests pass, confirming the setup is working correctly.

- Add Poetry package manager with pyproject.toml configuration
- Install pytest, pytest-cov, and pytest-mock as testing dependencies
- Configure pytest with custom markers (unit, integration, slow) and coverage settings
- Create organized testing directory structure (tests/, unit/, integration/)
- Add comprehensive conftest.py with reusable fixtures for temp files, mocks, and email testing
- Update .gitignore with testing artifacts, virtual environments, and IDE files
- Include validation tests to verify infrastructure setup works correctly
- Set 80% coverage threshold with HTML and XML reporting
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

Comments