Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 17, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the SimMIM project using Poetry as the package manager and pytest as the testing framework. The setup provides a ready-to-use testing environment where developers can immediately start writing tests.

Changes Made

Package Management

  • Poetry Configuration: Set up Poetry as the package manager with pyproject.toml
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Package Mode: Configured as package-mode = false for dependency management only

Testing Dependencies

Added the following development dependencies:

  • pytest (^7.4.0) - Core testing framework
  • pytest-cov (^4.1.0) - Coverage reporting
  • pytest-mock (^3.11.0) - Mocking utilities

Testing Configuration

Configured pytest in pyproject.toml with:

  • Test discovery patterns for test_*.py and *_test.py files
  • Coverage reporting for data, models, and root Python files
  • Multiple coverage output formats (terminal, HTML, XML)
  • Strict markers and configuration
  • Custom test markers: unit, integration, slow

Directory Structure

Created proper testing directory structure:

tests/
├── __init__.py
├── conftest.py
├── test_setup_validation.py
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory for test files
  • mock_config - Mock configuration object
  • sample_yaml_config - Sample YAML configuration file
  • mock_dataset - Mock dataset object
  • mock_model - Mock model object
  • sample_image_tensor - Sample image tensor for testing
  • captured_output - Capture stdout/stderr for testing
  • reset_modules - Auto-reset modules between tests

Additional Files

  • test.sh: Simple shell script for running tests
  • Validation Tests: Created test_setup_validation.py to verify the testing infrastructure

Configuration Updates

  • Updated .gitignore to include .claude/* for Claude-specific settings

How to Use

Install Dependencies

poetry install

Run Tests

You can run tests using any of these methods:

# Using Poetry directly
poetry run pytest

# Using the test script
./test.sh

# Run specific tests
poetry run pytest tests/test_setup_validation.py

# Run with coverage
poetry run pytest --cov

# Run tests by marker
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow

Coverage Reports

Coverage reports are generated in multiple formats:

  • Terminal output with missing lines
  • HTML report in htmlcov/ directory
  • XML report as coverage.xml

Notes

  • The coverage threshold requirement has been removed from the initial setup to allow for gradual test development
  • The project is configured to exclude test files and __pycache__ from coverage reporting
  • All validation tests are passing, confirming the infrastructure is properly set up
  • The _pil_interp import issue from timm is handled gracefully in the validation tests

Next Steps

Developers can now:

  1. Write unit tests in tests/unit/
  2. Write integration tests in tests/integration/
  3. Use the provided fixtures for common testing needs
  4. Run tests with coverage to track testing progress

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Set up pytest configuration with coverage reporting
- Create tests directory structure with unit/integration subdirectories
- Add comprehensive shared fixtures in conftest.py
- Configure test markers for unit, integration, and slow tests
- Update .gitignore with testing and Claude-specific entries
- Add validation tests to verify testing setup functionality
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