Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 16, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the BMW LabelTool Lite project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration as the project's package manager
  • Dependencies: Added testing dependencies as development dependencies:
    • pytest ^7.4.4 - Main testing framework
    • pytest-cov ^4.1.0 - Coverage reporting plugin
    • pytest-mock ^3.12.0 - Mocking utilities

Testing Configuration

  • Pytest Configuration: Configured in pyproject.toml with:

    • Automatic test discovery patterns
    • Coverage settings with 80% threshold
    • HTML and XML coverage report generation
    • Custom markers: unit, integration, slow
    • Strict mode enabled for better error detection
  • Coverage Configuration: Set up comprehensive coverage tracking:

    • Covers all three main modules: docker_sdk_api, inference_api, training_api
    • Excludes test files, cache, and virtual environments from coverage
    • Configured multiple report formats (terminal, HTML, XML)

Directory Structure

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

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • temp_dir - Temporary directory management
  • mock_config - Configuration mocking
  • mock_logger - Logger mocking
  • sample_image_path, sample_model_path - File fixtures
  • mock_request, mock_response - HTTP mocking
  • sample_training_data, sample_inference_data - Data fixtures
  • mock_docker_client - Docker client mocking
  • Additional fixtures for database, async operations, and file uploads

Development Commands

Configured Poetry scripts for running tests:

poetry run test    # Run all tests
poetry run tests   # Alternative command (both work)

All standard pytest options are available (e.g., -v, -k, -m, --no-cov)

Additional Setup

  • Updated .gitignore: Added comprehensive Python-specific entries including:

    • Testing artifacts (.pytest_cache/, coverage.xml, htmlcov/)
    • Claude-specific entries (.claude/*)
    • Virtual environments and IDE files
    • ML/AI specific files and directories
  • Validation Tests: Created test_infrastructure_validation.py to verify:

    • All directories and configuration files exist
    • Fixtures are properly available
    • Markers work correctly
    • Coverage is configured properly

How to Use

  1. Install Poetry (if not already installed):

    curl -sSL https://install.python-poetry.org | python3 -
  2. Install dependencies:

    poetry install
  3. Run tests:

    poetry run test              # Run all tests with coverage
    poetry run test -v           # Verbose output
    poetry run test -m unit      # Run only unit tests
    poetry run test -m "not slow" # Skip slow tests
    poetry run test --no-cov     # Run without coverage
  4. View coverage reports:

    • Terminal: Shown automatically after test run
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI integration

Notes

  • The project uses Python 3.9+ due to dependency requirements
  • Coverage threshold is set to 80% - tests will fail if coverage drops below this
  • The infrastructure is ready for immediate test writing - no actual unit tests for the codebase were created
  • Each microservice (docker_sdk_api, inference_api, training_api) is included in coverage tracking
  • Poetry lock file (poetry.lock) should be committed to ensure reproducible builds

- Set up Poetry package manager for dependency management
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage thresholds and custom markers
- Create test directory structure (unit/integration)
- Add shared fixtures in conftest.py for common test needs
- Configure test commands via Poetry scripts
- Update .gitignore with testing and Claude-specific entries
- Add 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