Skip to content

feat: Set up complete Python testing infrastructure with Poetry#62

Open
llbbl wants to merge 1 commit intosml2h3:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up complete Python testing infrastructure with Poetry#62
llbbl wants to merge 1 commit intosml2h3:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 26, 2025

Set Up Python Testing Infrastructure

Summary

This PR sets up a complete testing infrastructure for the Python 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 Setup: Configured Poetry as the package manager via pyproject.toml
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Lock File: Poetry will generate a poetry.lock file for reproducible builds

Testing Framework

  • pytest: Configured as the main testing framework (v8.0.0+)
  • pytest-cov: Added for coverage reporting (v5.0.0+)
  • pytest-mock: Included for mocking utilities (v3.14.0+)

Configuration

  • Test Discovery: Configured to find tests matching test_*.py or *_test.py patterns
  • Coverage Settings:
    • Reports in HTML, XML, and terminal formats
    • Covers configs, tools, and utils modules
    • Excludes nets and projects due to external dependencies
  • Custom Markers: Added unit, integration, and slow markers for test categorization

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared pytest fixtures
├── test_setup_validation.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Fixtures Available

The conftest.py file provides these reusable fixtures:

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • sample_yaml_config: Creates a sample YAML config file
  • mock_image_path: Mock image file path
  • mock_checkpoint_path: Mock checkpoint file path
  • sample_project_structure: Creates project directory structure
  • reset_modules: Auto-resets module imports between tests
  • capture_logs: Captures loguru logs for testing
  • mock_training_data: Provides mock training data

How to Use

Installation

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install project dependencies
poetry install

Running Tests

# Run all tests
poetry run test
# or
poetry run tests

# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

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

# Run with custom pytest options
poetry run pytest -v --tb=short

Coverage Reports

After running tests, coverage reports are available in:

  • Terminal: Displayed automatically after test run
  • HTML: htmlcov/index.html (open in browser)
  • XML: coverage.xml (for CI/CD integration)

Notes

  1. Dependencies: The project has some modules (nets) that require PyTorch, which isn't included in the base dependencies. These are excluded from coverage reporting.

  2. Python Version: Requires Python 3.8 or higher

  3. Poetry Lock File: The poetry.lock file should be committed to ensure consistent dependency versions across environments

  4. Test Organization: Tests should be organized into unit/ and integration/ subdirectories based on their scope

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 ensure code quality

- Add Poetry package manager configuration (pyproject.toml)
- Configure pytest with coverage reporting and custom markers
- Create testing directory structure (tests/unit, tests/integration)
- Add comprehensive pytest fixtures in conftest.py
- Set up Poetry script commands for running tests
- Add validation tests to verify infrastructure setup
- Update .gitignore with Claude-specific entries
- Migrate dependencies from requirements.txt to Poetry
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