Skip to content

Comments

feat: Set up Python testing infrastructure with Poetry#150

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

feat: Set up Python testing infrastructure with Poetry#150
llbbl wants to merge 1 commit intoEFForg:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 14, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the CrocodileHunter project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for developers to write and run tests with proper coverage reporting and organization.

Changes Made

Package Management

  • Migrated to Poetry: Set up Poetry as the modern Python package manager
  • Created pyproject.toml: Comprehensive configuration file with project metadata and dependencies
  • Migrated dependencies: Moved all dependencies from requirements.txt to Poetry's dependency management

Testing Framework

  • Added testing dependencies:
    • pytest (^7.4.0) - Main testing framework
    • pytest-cov (^4.1.0) - Coverage reporting
    • pytest-mock (^3.11.1) - Mocking utilities

Testing Configuration

  • Pytest configuration in pyproject.toml:

    • Test discovery patterns for test_*.py and *_test.py
    • Coverage reporting with HTML and XML outputs
    • Coverage threshold set to 80%
    • Custom markers: @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow
    • Strict mode with verbose output
  • Coverage configuration:

    • Source tracking for the src/ directory
    • Exclusions for test files, migrations, virtual environments, and cache directories
    • HTML report output to htmlcov/
    • XML report output to coverage.xml

Directory Structure

tests/
├── __init__.py
├── conftest.py                    # Shared fixtures and configuration
├── unit/                          # Unit tests directory
│   ├── __init__.py
│   └── test_example.py            # Example test file
├── integration/                   # Integration tests directory
│   └── __init__.py
└── test_infrastructure_validation.py  # Validation tests

Test Fixtures (conftest.py)

Created comprehensive fixtures for testing:

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • mock_database_session: Mock database session for testing
  • flask_test_client: Placeholder for Flask test client
  • sample_tower_data: Sample tower data for testing
  • sample_gps_data: Sample GPS data for testing
  • reset_environment: Reset environment variables between tests
  • mock_requests: Mock requests library for API testing
  • isolated_filesystem: Create isolated filesystem for file operations

Poetry Scripts

  • Added command shortcuts:
    • poetry run test - Run all tests
    • poetry run tests - Alternative command (both work)

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests with coverage
poetry run test

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

# Run tests with specific marker
poetry run pytest -m unit
poetry run pytest -m integration

# Run with verbose output
poetry run pytest -v

# Run without coverage
poetry run pytest --no-cov

Coverage Reports

After running tests, coverage reports are available in:

  • Terminal output (with missing lines)
  • htmlcov/index.html - HTML coverage report
  • coverage.xml - XML report for CI/CD integration

Validation

The setup has been validated with:

  • All dependencies successfully installed via Poetry
  • Validation tests passing (14/14 tests)
  • Test discovery working correctly
  • Fixtures functioning as expected
  • Coverage reporting generating properly

Notes

  1. Existing .gitignore: The project already has comprehensive gitignore entries for Python development, including test artifacts.

  2. Poetry Lock File: The poetry.lock file has been generated and should be committed to ensure reproducible builds.

  3. Virtual Environment: Poetry creates a virtual environment in .venv/ which is properly ignored by git.

  4. Coverage Threshold: Set to 80% as requested. The validation tests alone won't meet this threshold - actual unit tests for the codebase are needed.

Next Steps

  1. Write unit tests for the existing codebase modules in src/
  2. Add integration tests for API endpoints and database operations
  3. Configure CI/CD to run tests automatically
  4. Consider adding pre-commit hooks for test execution
  5. Add linting and type checking commands to pyproject.toml

The testing infrastructure is now ready for developers to start writing comprehensive tests for the CrocodileHunter project

- Replace Pipfile with Poetry configuration in pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure comprehensive pytest and coverage settings
- Create testing directory structure with unit/integration separation
- Add shared pytest fixtures in conftest.py
- Set up Poetry script commands for running tests
- Update .gitignore with testing and Claude entries
- Create 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