Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 29, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the validate_email Python project using Poetry for package management and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with complete project metadata migrated from setup.py
  • Dependency Management: Added testing dependencies as development dependencies:
    • pytest (^8.0.0) - Core testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with 80% threshold requirement
    • Multiple report formats: terminal, HTML, and XML
    • Custom markers: unit, integration, and slow
    • Strict mode enabled with verbose output
  • Coverage Configuration:

    • Source tracking for validate_email module
    • Exclusions for test files, virtual environments, and build artifacts
    • Precision reporting with line-level detail
    • Skip covered lines in terminal output for clarity

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_email_config: Mock email configuration data
  • mock_dns_resolver: Mock DNS resolver for MX lookups
  • mock_smtp_connection: Mock SMTP connection
  • sample_mx_records: Sample MX record data
  • network_timeout: Standard timeout value
  • test_data_dir: Path to test data directory

Development Commands

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)
  • Standard pytest options are available through these commands

Additional Updates

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Poetry files (excluding poetry.lock from gitignore as recommended)
    • Claude settings (.claude/*)
    • Virtual environments, IDE files, and temporary files

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test categories:

    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
  4. Generate coverage reports:

    • HTML report: htmlcov/index.html
    • XML report: coverage.xml
    • Terminal report: Automatically displayed

Notes

  • The coverage threshold is set to 80% but won't be enforced until actual tests are written
  • All infrastructure validation tests pass successfully
  • The setup follows Python testing best practices with clear separation of concerns
  • Poetry lock file is intentionally not gitignored to ensure reproducible builds

- Add Poetry package management with pyproject.toml configuration
- Configure pytest with coverage reporting (80% threshold)
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Create test directory structure with unit/integration separation
- Add shared fixtures in conftest.py for common test scenarios
- Include validation tests to verify infrastructure setup
- Update .gitignore with testing and development entries
- Configure Poetry scripts for 'test' and 'tests' commands
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