xmodaler
xmodaler copied to clipboard
feat: Set up comprehensive Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the xmodaler project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration - Dependency Migration: Migrated all dependencies from
requirements.txtto Poetry - Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
-
pytest Configuration:
- Test discovery patterns for
test_*.pyand*_test.pyfiles - Coverage reporting with HTML and XML output formats
- Custom markers for unit, integration, and slow tests
- Strict mode with proper error handling
- Test discovery patterns for
-
Coverage Settings:
- Source directory:
xmodaler - Excluded files: tests, init files, setup files
- Coverage threshold: Currently set to 0% (to be increased as tests are added)
- Multiple report formats: terminal, HTML, and XML
- Source directory:
Project Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_infrastructure.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Fixtures (conftest.py)
Created comprehensive fixtures including:
temp_dir/temp_file: Temporary file system utilitiesmock_config: Mock OmegaConf configurationmock_batch_data: Mock data batches for model testingcuda_available: CUDA availability checkerreset_random_seeds: Reproducibility helpermock_checkpoint_file: Testing checkpoint loadingmock_vocab_file: Testing tokenizationclean_environment: Environment variable managementmock_image_tensor/mock_feature_extractor: Image processing helpers
Additional Updates
-
Updated .gitignore: Added entries for:
- Testing artifacts (.pytest_cache, .coverage, htmlcov, coverage.xml)
- Claude settings (.claude/*)
- Poetry lock file (poetry.lock)
- Virtual environments and IDE files
-
Package Initialization: Added
xmodaler/__init__.pywith version info
Running Tests
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 specific test file
poetry run pytest tests/test_infrastructure.py
# Run tests with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run tests with coverage report
poetry run pytest --cov=xmodaler --cov-report=html
Next Steps
- Write Unit Tests: Create unit tests for individual components in
tests/unit/ - Write Integration Tests: Add integration tests in
tests/integration/ - Increase Coverage Threshold: Update
--cov-fail-underin pyproject.toml as test coverage improves - CI Integration: Configure GitHub Actions or other CI to run tests automatically
Notes
- The testing infrastructure is fully configured and validated
- All pytest features are available including fixtures, markers, and coverage
- The coverage threshold is currently set to 0% to allow initial setup without failing builds
- Both
poetry run testandpoetry run testscommands are configured for convenience