Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 20, 2025

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.toml with Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML output formats
    • Custom markers for unit, integration, and slow tests
    • Strict mode with proper error handling
  • 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

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 utilities
  • mock_config: Mock OmegaConf configuration
  • mock_batch_data: Mock data batches for model testing
  • cuda_available: CUDA availability checker
  • reset_random_seeds: Reproducibility helper
  • mock_checkpoint_file: Testing checkpoint loading
  • mock_vocab_file: Testing tokenization
  • clean_environment: Environment variable management
  • mock_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__.py with 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

  1. Write Unit Tests: Create unit tests for individual components in tests/unit/
  2. Write Integration Tests: Add integration tests in tests/integration/
  3. Increase Coverage Threshold: Update --cov-fail-under in pyproject.toml as test coverage improves
  4. 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 test and poetry run tests commands are configured for convenience

- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage, markers, and custom settings
- Create test directory structure (unit/integration subdirectories)
- Add comprehensive test fixtures in conftest.py
- Update .gitignore with testing and Poetry entries
- Create validation tests to verify infrastructure setup
- Configure test commands (poetry run test/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