plugin.googledrive
plugin.googledrive copied to clipboard
feat: Add Python testing infrastructure with Poetry and pytest
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.tomlwith 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_*.pyand*_test.pyfiles - Coverage reporting with HTML and XML output
- Custom markers for test categorization (
unit,integration,slow) - Strict mode with verbose output
- Test discovery patterns for
-
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)
- Source directory set to
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.locktracked) - Virtual environments and IDE files
- Claude-specific files (
.claude/*)
- Testing artifacts (
-
Validation Tests: Created
test_infrastructure.pyto 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:
- Write unit tests in the
tests/unit/directory - Write integration tests in the
tests/integration/directory - Use the provided fixtures to mock Kodi functionality
- Gradually increase the coverage threshold as more tests are added