platform-kendryte210 icon indicating copy to clipboard operation
platform-kendryte210 copied to clipboard

feat: Add comprehensive Python testing infrastructure

Open llbbl opened this issue 3 months ago • 0 comments

Add Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Kendryte210 platform project, providing developers with everything needed to write and run tests effectively.

Changes Made

Package Management

  • Added Poetry configuration in pyproject.toml with proper project metadata from platform.json
  • Configured development dependencies: pytest, pytest-cov, pytest-mock
  • Set up proper Python packaging with packages and include specifications

Testing Configuration

  • pytest configuration with comprehensive settings in pyproject.toml:
    • Test discovery patterns for test_*.py and *_test.py files
    • Custom markers: unit, integration, slow
    • Strict configuration for reliable testing
  • Coverage reporting configured with:
    • 80% coverage threshold requirement
    • HTML reports in htmlcov/ directory
    • XML reports for CI/CD integration
    • Proper exclusions for test files, examples, and virtual environments

Directory Structure

  • tests/ directory with proper Python package structure
  • tests/unit/ and tests/integration/ subdirectories for organized testing
  • tests/conftest.py with comprehensive shared fixtures:
    • temp_dir: Temporary directory for test files
    • mock_platform_config: Mock platform configuration data
    • mock_board_config: Mock board configuration data
    • mock_platformio_env: Mock PlatformIO environment
    • Sample file fixtures for testing

Validation Tests

  • Setup validation tests in tests/test_setup_validation.py:
    • Python version compatibility checks
    • Project structure validation
    • Configuration file validation
    • Import capability testing
    • Fixture functionality verification

Development Environment

  • Updated .gitignore with testing-related entries and Claude Code settings
  • Poetry lock file for reproducible dependency management

Running Tests

Installation

poetry install

Running Tests

# Run all tests
poetry run pytest

# Run with coverage
poetry run pytest --cov

# Run specific test types
poetry run pytest -m unit          # Only unit tests
poetry run pytest -m integration   # Only integration tests
poetry run pytest -m "not slow"    # Exclude slow tests

# Run with verbose output
poetry run pytest -v

# Generate coverage report
poetry run pytest --cov --cov-report=html

Coverage Reports

  • Terminal: Coverage summary displayed after test runs
  • HTML: Open htmlcov/index.html in browser for detailed coverage report
  • XML: coverage.xml for CI/CD integration

Infrastructure Features

  • 80% coverage threshold ensures code quality
  • Multiple test markers for flexible test organization
  • Comprehensive fixtures for platform and board testing
  • Proper exclusions prevent coverage pollution from test files
  • Reproducible environment via Poetry lock file

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use provided fixtures for consistent test setup
  4. Run tests with confidence in the infrastructure
  5. Monitor code coverage to maintain quality standards

The testing infrastructure is ready for immediate use and follows Python testing best practices.

llbbl avatar Sep 03 '25 18:09 llbbl