Flatcar icon indicating copy to clipboard operation
Flatcar copied to clipboard

chore: set up Python testing infrastructure with Poetry

Open llbbl opened this issue 5 months ago • 0 comments

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.toml with 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 framework
  • pytest-cov (^5.0.0) - Coverage reporting plugin
  • pytest-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, and slow markers
  • 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 creation
  • mock_config - Configuration object mocking
  • mock_env - Environment variable mocking
  • sample_data - Test data provision
  • mock_requests - HTTP request mocking
  • capture_logs - Log output capture

Additional Setup

  • Updated .gitignore: Added Python, testing, and Claude-specific patterns
  • Test Runner Scripts: Created ./test and ./run-tests executable 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:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures for common testing needs
  4. Run tests with coverage reporting to ensure code quality

llbbl avatar Jun 28 '25 19:06 llbbl