Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Sep 1, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the DCF77 MutterUhr project, providing a solid foundation for writing and running tests in a Python development environment.

Changes Made

Package Management

  • Added Poetry configuration in pyproject.toml with project metadata and dependencies
  • Configured development dependencies: pytest, pytest-cov, pytest-mock
  • Set up Poetry scripts for easy test execution (poetry run test and poetry run tests)

Testing Configuration

  • Comprehensive pytest configuration with:
    • Test discovery patterns for various test file naming conventions
    • Coverage reporting with 80% threshold
    • HTML and XML coverage report generation
    • Custom markers for unit, integration, and slow tests
    • Strict configuration for better test reliability

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test utilities
├── test_setup_validation.py # Validation tests for infrastructure
├── unit/
│   └── __init__.py         # Unit test directory
└── integration/
    └── __init__.py         # Integration test directory

Testing Utilities

  • Comprehensive fixtures in conftest.py:
    • temp_dir - Temporary directory for file system tests
    • mock_machine_pin, mock_machine_rtc - Hardware mocking for MicroPython modules
    • mock_network - WiFi/network functionality mocking
    • mock_urequests - HTTP request mocking
    • mock_secrets - Credentials mocking
    • mock_microdot - Web framework mocking
    • Sample data fixtures for testing

Development Environment

  • Updated .gitignore with comprehensive exclusions:
    • Testing artifacts (.pytest_cache/, htmlcov/, .coverage)
    • Virtual environments and build artifacts
    • IDE files and OS-specific files
    • Claude Code settings

Validation

  • Created validation test suite that verifies:
    • pytest functionality and Python version compatibility
    • Project structure integrity
    • Custom test markers functionality
    • Fixture availability and mocking capabilities

How to Run Tests

Install Dependencies

poetry install

Run All Tests

poetry run pytest
# or
poetry run test
# or  
poetry run tests

Run Specific Test Categories

# Unit tests only
poetry run pytest -m unit

# Integration tests only
poetry run pytest -m integration

# Exclude slow tests
poetry run pytest -m "not slow"

Generate Coverage Reports

poetry run pytest --cov-report=html
# Open htmlcov/index.html in browser to view coverage

Notes

  • MicroPython Compatibility: The main application files (main.py, webtime.py) are MicroPython-specific and excluded from standard Python coverage analysis
  • Hardware Mocking: Comprehensive mocking fixtures are provided for testing code that interacts with MicroPython hardware modules
  • Ready for Development: The infrastructure is immediately ready for developers to start writing unit and integration tests
  • Coverage Configured: HTML and XML coverage reports are generated automatically, with an 80% coverage threshold

Testing Infrastructure Validation

All validation tests pass successfully:

  • ✅ pytest functionality verified
  • ✅ Python version compatibility confirmed
  • ✅ Project structure validated
  • ✅ Custom markers working correctly
  • ✅ Shared fixtures accessible and functional
  • ✅ Mocking capabilities operational

The testing infrastructure is now ready for active development and continuous integration workflows.

- Added Poetry package manager with pyproject.toml configuration
- Configured pytest with coverage reporting, custom markers, and strict options
- Created complete testing directory structure (tests/, unit/, integration/)
- Added comprehensive shared fixtures for mocking MicroPython modules
- Set up .gitignore with testing and development environment entries
- Created validation test suite to verify infrastructure functionality
- Configured development scripts for running tests via Poetry
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