Skip to content

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

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

feat: Set up comprehensive Python testing infrastructure with Poetry#34
llbbl wants to merge 1 commit intodropreg:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 28, 2025

Add Python Testing Infrastructure

Summary

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

Changes Made

Package Management

  • Poetry Configuration: Added pyproject.toml with Poetry configuration as the primary package manager
  • Dependencies: Added testing dependencies as development dependencies:
    • pytest (^7.4.3) - Core testing framework
    • pytest-cov (^4.1.0) - Coverage reporting plugin
    • pytest-mock (^3.12.0) - Mocking utilities

Testing Configuration

  • pytest Configuration in pyproject.toml:
    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML, XML, and terminal output
    • Custom markers for test categorization (unit, integration, slow)
    • Strict mode enabled for better test quality
    • Coverage configured for all three source directories

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and configuration
├── test_infrastructure_validation.py  # Infrastructure validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Testing Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory management
  • mock_config - Mock configuration for testing
  • sample_data - Sample data for tests
  • mock_model_output - Mock PyTorch tensors
  • mock_file_system - Mock file system structure
  • capture_logs - Log capturing for tests
  • disable_gpu - Force CPU-only execution
  • Auto-marking based on test location

Additional Setup

  • .gitignore: Updated with Python and testing-related entries
  • Poetry lock file: Generated and tracked for reproducible builds
  • Validation tests: Created to verify the infrastructure works correctly

How to Use

Installation

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

# Install dependencies
poetry install

Running Tests

# Run all tests
poetry run test

# Alternative command (both work)
poetry run tests

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

# Run specific test file
poetry run pytest tests/test_infrastructure_validation.py

# Run with coverage report
poetry run pytest --cov-report=html

Writing Tests

  1. Unit Tests: Place in tests/unit/ directory
  2. Integration Tests: Place in tests/integration/ directory
  3. Use fixtures: Import from conftest.py for common test scenarios
  4. Mark tests: Use @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow

Notes

  • Coverage threshold is currently set to 0% to allow infrastructure setup. This should be increased as actual tests are added.
  • The existing setup.py files in subdirectories are preserved for compatibility
  • Poetry is configured to include all three main source directories as packages
  • All tests pass validation, confirming the infrastructure is properly set up

Next Steps

  1. Start writing unit tests for core R-Drop functionality
  2. Add integration tests for the different model implementations
  3. Gradually increase coverage threshold as tests are added
  4. Consider adding additional testing tools (e.g., hypothesis for property-based testing)

- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage reporting and custom markers
- Create test directory structure with unit/integration separation
- Add pytest fixtures for common testing scenarios
- Configure .gitignore with testing-related entries
- Add validation tests to verify infrastructure setup

Test commands available:
- poetry run test
- poetry run tests
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