Skip to content

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

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

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

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 15, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the Flask application builder project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration as the package manager
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry format
  • Python Version: Set minimum Python version to 3.9 (required by yarl dependency)

Testing Setup

  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
  • Directory Structure:
    tests/
    ├── __init__.py
    ├── conftest.py
    ├── test_setup_validation.py
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Configuration

  • pytest Configuration in pyproject.toml:

    • Test discovery patterns for files, classes, and functions
    • Coverage reporting with 80% threshold
    • Output formats: terminal, HTML, and XML
    • Custom markers: unit, integration, slow
    • Strict mode enabled for better error detection
  • Coverage Configuration:

    • Source code coverage tracking
    • Exclusions for test files, virtual environments, and generated files
    • HTML and XML report generation
    • 80% coverage requirement

Development Experience

  • Poetry Scripts: Added test and tests commands for running pytest
  • Shared Fixtures in conftest.py:
    • temp_dir: Temporary directory management
    • mock_env_vars: Environment variable mocking
    • sample_config: Test configuration data
    • flask_app & flask_client: Flask testing utilities
    • mock_file_operations: File operation mocking
    • Various sample data fixtures

Other Changes

  • .gitignore: Comprehensive Python gitignore with testing artifacts and Claude-specific entries
  • Validation Tests: Created test_setup_validation.py to verify the infrastructure setup

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

    poetry run test
    # or
    poetry run tests
  3. Run tests with specific markers:

    poetry run pytest -m unit
    poetry run pytest -m integration
    poetry run pytest -m "not slow"
  4. Run tests without coverage (useful during development):

    poetry run pytest --no-cov
  5. View coverage report:

    • HTML report: Open htmlcov/index.html in a browser
    • XML report: Available at coverage.xml for CI integration

Notes

  • The current codebase has low test coverage (26.74%) as no actual unit tests for the application code have been written yet
  • The validation tests confirm that all testing infrastructure components are properly installed and configured
  • Poetry lock file (poetry.lock) should be committed to ensure reproducible builds
  • The 80% coverage threshold will need to be met as developers add tests for the application code

Next Steps

Developers can now immediately start writing tests for the Flask application by:

  1. Adding unit tests in tests/unit/
  2. Adding integration tests in tests/integration/
  3. Using the provided fixtures from conftest.py
  4. Following the established testing patterns

- Add Poetry as package manager with pyproject.toml configuration
- Migrate all dependencies from requirements.txt to Poetry
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Configure pytest with custom markers and coverage thresholds
- Create testing directory structure with unit/integration folders
- Add comprehensive shared fixtures in conftest.py
- Update .gitignore with testing and Claude-specific entries
- Add validation tests to verify infrastructure setup
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