Flatcar
Flatcar copied to clipboard
chore: set up Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the Flatcar Linux Python codebase using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Migrated existing dependencies from
sync-maintainers/requirements.txt - Package Mode: Configured as non-package mode since this is a repository with scripts
Testing Dependencies
Added the following development dependencies:
pytest(^8.0.0) - Core testing frameworkpytest-cov(^5.0.0) - Coverage reporting pluginpytest-mock(^3.14.0) - Mocking utilities
Testing Configuration
Configured in pyproject.toml:
- Test Discovery: Configured patterns for finding test files
- Coverage Settings: Set up with 80% threshold (currently disabled for validation tests)
- Custom Markers: Added
unit,integration, andslowmarkers - Strict Mode: Enabled strict markers and configuration
Directory Structure
Created standard testing structure:
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Infrastructure validation
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
Implemented common fixtures:
temp_dir- Temporary directory creationmock_config- Configuration object mockingmock_env- Environment variable mockingsample_data- Test data provisionmock_requests- HTTP request mockingcapture_logs- Log output capture
Additional Setup
- Updated .gitignore: Added Python, testing, and Claude-specific patterns
- Test Runner Scripts: Created
./testand./run-testsexecutable scripts - Validation Tests: Added comprehensive tests to verify the infrastructure
Running Tests
Install Dependencies
poetry install
Run Tests
Using Poetry directly:
poetry run pytest
Using the provided scripts:
./test
# or
./run-tests
Run with Coverage
poetry run pytest --cov=sync-maintainers --cov-report=html
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"
Notes
- The project uses Poetry in non-package mode since this is a repository containing scripts rather than a distributable package
- Coverage is currently configured to check test files only (for validation purposes) but should be updated to check actual source code when tests are written
- The validation tests verify that all infrastructure components are properly installed and configured
- All pytest standard options are available when running tests
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 for common testing needs
- Run tests with coverage reporting to ensure code quality