Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 15, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the VAmPI project using Poetry for dependency management and pytest as the testing framework. The setup provides a foundation for writing unit and integration tests with proper coverage reporting.

Changes Made

Package Management

  • Migrated from requirements.txt to Poetry (pyproject.toml)
  • Configured Poetry with package-mode = false for non-distributable projects
  • Created poetry.lock file to ensure reproducible builds

Testing Dependencies

Added the following development dependencies:

  • pytest (^7.4.0) - Main testing framework
  • pytest-cov (^4.1.0) - Coverage reporting integration
  • pytest-mock (^3.11.0) - Mocking utilities for tests

Testing Configuration

Configured comprehensive testing settings in pyproject.toml:

  • Test discovery: Configured paths and naming patterns
  • Coverage settings:
    • 80% coverage threshold requirement
    • HTML and XML report generation
    • Branch coverage enabled
    • Exclusion patterns for non-testable code
  • Custom markers: unit, integration, and slow for test categorization
  • Strict mode: Enabled strict markers and configuration

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures
├── test_infrastructure_only.py  # Validation tests
├── test_setup_validation.py     # Additional validation
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures

Created reusable fixtures in conftest.py:

  • temp_dir - Temporary directory for test files
  • mock_config - Mock Flask configuration
  • sample_user_data - Test user data
  • sample_book_data - Test book data
  • capture_logs - Log capturing utility

Additional Updates

  • Updated .gitignore to exclude testing artifacts and Claude settings
  • Updated CLAUDE.md with testing commands documentation

Running Tests

Basic Commands

# Install dependencies
poetry install

# Run all tests
poetry run pytest

# Run with verbose output
poetry run pytest -v

# Run specific test file
poetry run pytest tests/test_infrastructure_only.py

# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration

Coverage Commands

# Run with coverage report
poetry run pytest --cov

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

# Skip coverage for validation
poetry run pytest --no-cov

Notes

  1. Circular Import Issue: The application has circular imports between app.py, config.py, and model files. Tests that import the app will fail until this is resolved. The infrastructure validation tests work without importing the app.

  2. Poetry Scripts: The poetry run test and poetry run tests commands are configured but show warnings due to the package-mode setting. Use poetry run pytest directly for now.

  3. Coverage Threshold: The 80% coverage requirement is configured but will fail until actual unit tests are written for the application code.

Next Steps

  1. Resolve circular import issues in the application code
  2. Write unit tests for API views and models
  3. Write integration tests for API endpoints
  4. Set up CI/CD pipeline to run tests automatically

- Set up Poetry for dependency management and migrate from requirements.txt
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage thresholds, custom markers, and reporting
- Create test directory structure with unit/integration separation
- Add shared fixtures in conftest.py for common test scenarios
- Update .gitignore with testing artifacts and Claude settings
- Include 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