feat: Set up comprehensive Python testing infrastructure with Poetry
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.tomlwith Poetry configuration - Preserved all dependencies: Migrated all 29 dependencies from
requirements.txt - Python version: Set to
^3.9to meet accelerate package requirements - Note:
xformersdependency temporarily commented out due to build issues
Testing Framework Setup
- Added testing dependencies:
pytest(^8.0.0) - Core testing frameworkpytest-cov(^5.0.0) - Coverage reportingpytest-mock(^3.14.0) - Mocking utilities
Testing Configuration
-
Pytest configuration in
pyproject.toml:- Test discovery patterns for
test_*.pyand*_test.py - Custom markers:
unit,integration,slow - Coverage reporting with HTML and XML output
- Strict mode with verbose output
- Automatic coverage report generation
- Test discovery patterns for
-
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)
- Source directory:
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 managementmock_config: Sample configuration dictionarysample_tensor: PyTorch tensor for testingsample_text_data: Text data for NLP testsmock_model: Mock PyTorch modelmock_tokenizer: Mock tokenizersample_image_path: Temporary image file creationenvironment_variables: Safe environment variable managementmock_api_response: API response mockingreset_random_seeds: Automatic seed reset for reproducibilitycapture_logs: Log message capture during tests
Development Commands
Both commands are configured to run the full test suite:
poetry run testpoetry 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.lockis NOT ignored (as required)
Instructions for Running Tests
-
Install dependencies:
poetry install -
Run all tests:
poetry run test # or poetry run tests -
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 -
View coverage report:
- Terminal: Automatically displayed after test run
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor CI integration
Notes
-
Coverage Threshold: Currently set to 0% to allow initial setup validation. Should be changed to 80% in
pyproject.tomlonce actual tests are written:- Line 66:
--cov-fail-under=80 - Line 101:
fail_under = 80
- Line 66:
-
xformers: This dependency is commented out due to build issues. It may need special installation instructions or system dependencies.
-
Validation Tests: The included
test_setup_validation.pyverifies that all testing infrastructure components are working correctly. These tests can be removed once real tests are added.
Next Steps
- Developers can now immediately start writing tests in the
tests/unit/andtests/integration/directories - Update coverage thresholds to 80% once tests are written
- Consider adding GitHub Actions workflow for CI/CD
- Investigate xformers build requirements if needed
The testing infrastructure is now ready for immediate use!
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.