Skip to content

feat: Add Python testing infrastructure with Poetry and pytest#352

Open
llbbl wants to merge 1 commit intocguZZman:matrixfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Add Python testing infrastructure with Poetry and pytest#352
llbbl wants to merge 1 commit intocguZZman:matrixfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jul 1, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete Python testing infrastructure for the Google Drive Kodi plugin 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 primary package manager
  • Dependencies: Added testing dependencies as development dependencies:
    • pytest (^8.0.0) - Main testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities

Testing Configuration

  • pytest Configuration: Set up comprehensive pytest settings in pyproject.toml:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML output
    • Custom markers for test categorization (unit, integration, slow)
    • Strict mode with verbose output
  • Coverage Configuration:

    • Source directory set to resources/
    • Exclusions for test files, virtual environments, and cache directories
    • Coverage threshold currently set to 0% (to be increased as tests are added)

Directory Structure

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

Test Fixtures

Created comprehensive fixtures in conftest.py for Kodi plugin development:

  • temp_dir - Temporary directory management
  • mock_addon - Mock Kodi addon object
  • mock_xbmc, mock_xbmcgui, mock_xbmcplugin - Mock Kodi modules
  • mock_kodi_modules - Combined fixture that injects all mocks into sys.modules
  • sample_drive_item, sample_folder_item - Sample Google Drive data
  • mock_settings - Common plugin settings
  • mock_http_response - Mock HTTP responses for API testing
  • capture_logs - Log capture for testing

Additional Setup

  • Updated .gitignore: Added entries for:

    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
    • Poetry files (keeping poetry.lock tracked)
    • Virtual environments and IDE files
    • Claude-specific files (.claude/*)
  • Validation Tests: Created test_infrastructure.py to verify:

    • All testing dependencies are installed correctly
    • Project structure exists as expected
    • Fixtures are properly loaded
    • Test markers work correctly
    • Kodi module mocking functions properly

How to Use

Running Tests

You can run tests using either of these commands:

poetry run test
poetry run tests

Both commands will:

  • Execute all tests in the tests/ directory
  • Generate coverage reports in terminal, HTML, and XML formats
  • Apply all pytest configurations from pyproject.toml

Running Specific Test Categories

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests  
poetry run pytest -m integration

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

Installing Dependencies

# Install all dependencies including dev dependencies
poetry install

# Install only production dependencies
poetry install --no-dev

Notes

  • The coverage threshold is currently set to 0% to allow the infrastructure to be set up without existing tests. This should be increased to 80% (or your preferred threshold) as tests are added.
  • The validation tests all pass, confirming the infrastructure is working correctly.
  • The Poetry scripts show a warning about entry points, but this doesn't affect functionality.
  • All Kodi-specific modules are mocked to allow testing without a Kodi environment.

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures to mock Kodi functionality
  4. Gradually increase the coverage threshold as more tests are added

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting and custom markers
- Create test directory structure with unit/integration subdirs
- Add comprehensive conftest.py with Kodi-specific fixtures
- Update .gitignore with testing and Poetry entries
- Add validation tests to verify infrastructure setup
- Configure test commands accessible via `poetry run test[s]`
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