Skip to content

feat: Set up comprehensive Python testing infrastructure#103

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

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

Conversation

@llbbl

@llbbl llbbl commented Sep 4, 2025

Copy link
Copy Markdown

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the osmand-osm project, providing all necessary tools and configurations for developers to write and run tests effectively.

What's Added

  • Package Management: Poetry configuration in pyproject.toml with proper dependency management
  • Testing Framework: pytest with coverage reporting, mocking utilities, and custom markers
  • Directory Structure: Organized testing structure with separate unit and integration test directories
  • Shared Fixtures: Comprehensive set of reusable test fixtures for common testing scenarios
  • Configuration: Pytest and coverage configurations with 80% coverage threshold
  • Validation: Infrastructure validation tests to ensure everything works correctly

Testing Infrastructure Components

Package Manager

  • Poetry set up as the primary package manager
  • Dependencies properly categorized (dev vs production)
  • Optional dependencies for database connections

Testing Dependencies

  • pytest - Main testing framework
  • pytest-cov - Coverage reporting with HTML, XML, and terminal output
  • pytest-mock - Enhanced mocking utilities

Directory Structure

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

Configuration Features

  • pytest.ini_options: Test discovery, strict markers, verbose output
  • coverage settings: 80% threshold, multiple report formats, exclusion patterns
  • test markers: unit, integration, slow for test categorization

Shared Fixtures

  • temp_dir - Temporary directory management
  • mock_config - Configuration mocking
  • mock_db_connection - Database connection mocking
  • sample_geojson_data - GeoJSON test data
  • sample_osm_data - OSM XML test data
  • mock_working_area - WorkingArea object mocking
  • And more...

Running Tests

After this PR, developers can run tests using:

# Install dependencies
poetry install --only=dev

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov=osmand_osm

# Run specific test categories
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

# Run tests in specific directories
poetry run pytest tests/unit/
poetry run pytest tests/integration/

Coverage Reporting

The setup generates coverage reports in multiple formats:

  • Terminal: Shows missing lines during test runs
  • HTML: Detailed report in htmlcov/ directory
  • XML: Machine-readable report for CI/CD integration

Validation

The infrastructure includes validation tests (tests/test_infrastructure.py) that verify:

  • Python version compatibility
  • Pytest functionality
  • Fixture availability and functionality
  • Configuration correctness
  • Test markers
  • Mock capabilities
  • Temporary file handling
  • Environment setup

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

Notes

  • The setup uses optional dependencies to handle cases where system libraries (like GDAL) might not be available
  • .gitignore updated with comprehensive entries for testing artifacts, Python files, and development tools
  • Infrastructure is designed to be extensible - developers can easily add more fixtures and test utilities

🤖 Generated with Claude Code

- Add Poetry package manager with pyproject.toml configuration
- Create testing dependencies (pytest, pytest-cov, pytest-mock)
- Implement pytest configuration with 80% coverage threshold
- Set up testing directory structure (tests/, tests/unit/, tests/integration/)
- Add comprehensive shared fixtures in conftest.py
- Create .gitignore with testing and development entries
- Add infrastructure validation tests to verify setup works
- Configure coverage reporting (HTML, XML, terminal)
- Set up custom test markers (unit, integration, slow)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
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