Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Sep 3, 2025

Set up comprehensive Python testing infrastructure

Summary

This PR establishes a complete testing infrastructure for the GIS Python tools project, providing developers with a ready-to-use testing environment that follows Python best practices.

Changes Made

Package Management

  • Poetry Setup: Configured Poetry as the package manager with pyproject.toml
  • Dependency Management: Added testing dependencies as dev 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: Comprehensive pytest setup in pyproject.toml including:

    • Test discovery patterns (test_*.py, *_test.py)
    • Custom markers: unit, integration, slow
    • Strict configuration for better test reliability
    • Test path configuration pointing to tests/ directory
  • Coverage Configuration: Configured coverage reporting with:

    • 80% coverage threshold (configurable)
    • HTML and XML report generation
    • Source code inclusion/exclusion patterns
    • Exclusion of test files, virtual environments, and common non-source files

Directory Structure

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

Shared Testing Fixtures

Created comprehensive conftest.py with fixtures for:

  • File Operations: temp_dir, temp_file, mock_file_system
  • GIS Data: sample_geojson_data, sample_csv_data, sample_coordinates, sample_polygon_coords
  • Mocking: mock_logger, mock_config, mock_shapefile, mock_gdal_dataset, mock_qgis
  • Environment: clean_environment, test_data_dir
  • Data Types: sample_raster_data with NumPy array support

Development Environment

  • .gitignore: Comprehensive exclusions for:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, coverage.xml)
    • Claude Code settings (.claude/)
    • Python artifacts (__pycache__/, *.pyc, build directories)
    • Virtual environments and IDE files
    • Geospatial data files (with exceptions for test data)

Validation Tests

  • Infrastructure Validation: Created comprehensive test suite to verify:
    • Basic pytest functionality
    • All fixture functionality
    • Custom marker usage (unit, integration, slow)
    • Mocking capabilities
    • File operations and temporary directory handling
    • Parametrized testing
    • Exception handling

Testing Instructions

Running Tests

# Install dependencies (first time only)
poetry install

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=. --cov-report=html --cov-report=xml

# Run specific test types
poetry run pytest -m unit          # Unit tests only
poetry run pytest -m integration   # Integration tests only  
poetry run pytest -m slow          # Slow tests only
poetry run pytest -m "not slow"    # Exclude slow tests

# Verbose output
poetry run pytest -v

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

Coverage Reports

  • HTML Report: Open htmlcov/index.html in browser
  • XML Report: Available at coverage.xml
  • Terminal: Coverage summary displayed after test run

Validation Results

26/26 tests passing in validation suite
All fixtures working correctly
Coverage reporting functional (HTML + XML)
Custom markers working (unit, integration, slow)
Mocking capabilities verified (pytest-mock)

Development Notes

  • Poetry Lock File: The poetry.lock file is intentionally not in .gitignore to ensure reproducible builds
  • Coverage Threshold: Set to 80% but can be adjusted in pyproject.toml under [tool.coverage.report]
  • Test Discovery: Configured to automatically discover tests following naming conventions
  • Fixture Scope: Most fixtures use function scope; test_data_dir uses session scope for performance

Ready for Development

The testing infrastructure is now complete and ready for developers to:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use shared fixtures from conftest.py
  4. Generate coverage reports to track test coverage
  5. Use custom markers to organize and filter tests

All testing best practices are implemented and the infrastructure has been thoroughly validated.

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Create testing directory structure (tests/, unit/, integration/)
- Configure pytest with custom markers (unit, integration, slow)
- Set up coverage reporting with 80% threshold and HTML/XML output
- Add comprehensive shared fixtures in conftest.py for GIS testing
- Create .gitignore with testing and development environment exclusions
- Add validation test suite to verify infrastructure functionality
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