Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 25, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Ovis project, migrating from traditional setuptools to Poetry for modern dependency management and adding a complete pytest-based testing framework.

Changes Made

Package Management Migration

  • Migrated to Poetry: Created pyproject.toml with Poetry configuration
  • Preserved all dependencies: Migrated all 29 dependencies from requirements.txt
  • Python version: Set to ^3.9 to meet accelerate package requirements
  • Note: xformers dependency temporarily commented out due to build issues

Testing Framework Setup

  • Added testing dependencies:
    • pytest (^8.0.0) - Core testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities

Testing Configuration

  • Pytest configuration in pyproject.toml:

    • Test discovery patterns for test_*.py and *_test.py
    • Custom markers: unit, integration, slow
    • Coverage reporting with HTML and XML output
    • Strict mode with verbose output
    • Automatic coverage report generation
  • Coverage configuration:

    • Source directory: ovis
    • Excluded: test files, migrations, __init__.py
    • Report formats: terminal, HTML, XML
    • Coverage threshold: Currently 0% (TODO: change to 80% when tests are added)

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • mock_config: Sample configuration dictionary
  • sample_tensor: PyTorch tensor for testing
  • sample_text_data: Text data for NLP tests
  • mock_model: Mock PyTorch model
  • mock_tokenizer: Mock tokenizer
  • sample_image_path: Temporary image file creation
  • environment_variables: Safe environment variable management
  • mock_api_response: API response mocking
  • reset_random_seeds: Automatic seed reset for reproducibility
  • capture_logs: Log message capture during tests

Development Commands

Both commands are configured to run the full test suite:

  • poetry run test
  • poetry run tests

Updated .gitignore

Added comprehensive entries for:

  • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, etc.)
  • Claude settings (.claude/*)
  • Python build artifacts
  • Virtual environments
  • IDE files
  • Note: poetry.lock is NOT ignored (as required)

Instructions for Running Tests

  1. Install dependencies:

    poetry install
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test categories:

    poetry run pytest -m unit        # Unit tests only
    poetry run pytest -m integration # Integration tests only
    poetry run pytest -m "not slow"  # Exclude slow tests
  4. View coverage report:

    • Terminal: Automatically displayed after test run
    • HTML: Open htmlcov/index.html in a browser
    • XML: Available at coverage.xml for CI integration

Notes

  1. Coverage Threshold: Currently set to 0% to allow initial setup validation. Should be changed to 80% in pyproject.toml once actual tests are written:

    • Line 66: --cov-fail-under=80
    • Line 101: fail_under = 80
  2. xformers: This dependency is commented out due to build issues. It may need special installation instructions or system dependencies.

  3. Validation Tests: The included test_setup_validation.py verifies that all testing infrastructure components are working correctly. These tests can be removed once real tests are added.

Next Steps

  1. Developers can now immediately start writing tests in the tests/unit/ and tests/integration/ directories
  2. Update coverage thresholds to 80% once tests are written
  3. Consider adding GitHub Actions workflow for CI/CD
  4. Investigate xformers build requirements if needed

The testing infrastructure is now ready for immediate use!

- Migrated from setuptools to Poetry for modern dependency management
- Added pytest, pytest-cov, and pytest-mock as development dependencies
- Configured pytest with custom markers (unit, integration, slow)
- Set up coverage reporting with HTML and XML output formats
- Created test directory structure with conftest.py and shared fixtures
- Added validation tests to verify testing infrastructure
- Updated .gitignore with testing artifacts and Claude settings
- Note: xformers dependency commented out due to build issues
- Coverage threshold temporarily set to 0% (change to 80% when adding tests)
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants