Skip to content

feat: Set up comprehensive Python testing infrastructure - #4

Open
llbbl wants to merge 1 commit into
jeremytarling:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure#4
llbbl wants to merge 1 commit into
jeremytarling:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl

@llbbl llbbl commented Sep 2, 2025

Copy link
Copy Markdown

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Flask-based tarot webapp, providing developers with a robust foundation for writing and running tests.

Changes Made

Package Management

  • Added Poetry as the package manager with pyproject.toml configuration
  • Migrated dependencies from requirements.txt to Poetry format
  • Maintained existing Flask 2.2.5 and gunicorn dependencies

Testing Framework

  • Added pytest as the primary testing framework
  • Added pytest-cov for coverage reporting with 80% threshold
  • Added pytest-mock for enhanced mocking capabilities
  • All testing dependencies added as development dependencies

Testing Configuration

  • Comprehensive pytest configuration in pyproject.toml:
    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting in HTML, XML, and terminal formats
    • Strict configuration and custom markers (unit, integration, slow)
    • Configured to cover the webapp package

Directory Structure

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

Shared Test Fixtures

The tests/conftest.py provides common fixtures:

  • temp_dir - Temporary directory for file operations
  • temp_file - Temporary file with test content
  • mock_config - Mock configuration object
  • mock_flask_app - Mock Flask app instance
  • clean_environment - Environment variable cleanup
  • sample_data - Sample data for testing

Updated Configuration

  • Enhanced .gitignore with Python, testing, and development-related entries
  • Coverage configuration to exclude test files and virtual environments
  • Proper TOML formatting with escaped regex patterns

Running Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest

Run Tests Without Coverage

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

Generate Coverage Reports

Coverage reports are automatically generated:

  • HTML Report: htmlcov/index.html
  • XML Report: coverage.xml
  • Terminal: Shows missing lines

Validation

The setup includes validation tests (test_setup_validation.py) that verify:

  • ✅ Python version compatibility (3.8+)
  • ✅ Project structure integrity
  • ✅ Testing directory structure
  • ✅ Shared fixtures functionality
  • ✅ Pytest markers configuration

All validation tests pass successfully, confirming the infrastructure is ready for use.

Notes

  • The original requirements.txt is preserved for compatibility
  • Poetry lock file is included in version control for reproducible builds
  • Coverage threshold is set to 80% but can be adjusted in pyproject.toml
  • The infrastructure is ready for immediate use - developers can start writing tests for the webapp components

Next Steps

Developers can now:

  1. Write unit tests for webapp/cards.py and webapp/routes.py
  2. Create integration tests for Flask routes and templates
  3. Add more specific fixtures as needed
  4. Utilize the existing shared fixtures for common test scenarios

- Add Poetry package manager with pyproject.toml configuration
- Migrate existing dependencies from requirements.txt
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (80% threshold)
- Set up testing directory structure (tests/unit, tests/integration)
- Create shared fixtures in conftest.py for common test utilities
- Add comprehensive .gitignore for Python projects and testing artifacts
- Include validation tests to verify setup functionality
- Configure HTML and XML coverage report generation
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