Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry#87

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

feat: Add comprehensive Python testing infrastructure with Poetry#87
llbbl wants to merge 1 commit intoalibaba:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 26, 2025

Python Testing Infrastructure Setup

Summary

This PR sets up a comprehensive testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework. The infrastructure is now ready for developers to immediately start writing tests.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with full Poetry configuration
  • Dependency Migration: Migrated all dependencies from requirements.txt to Poetry
  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies

Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns
    • Set up coverage reporting with HTML and XML output
    • Added custom markers for unit, integration, and slow tests
    • Configured strict mode for better test quality
  • Coverage Settings:

    • Source directories: models, utils, stable_lora
    • Coverage reports: Terminal, HTML (htmlcov/), and XML (coverage.xml)
    • Note: Coverage threshold temporarily set to 0% for setup. Should be changed to 80% when adding actual tests

Directory Structure

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

Test Fixtures (in conftest.py)

  • temp_dir: Temporary directory with automatic cleanup
  • mock_config: Mock OmegaConf configuration
  • sample_image_path: Mock image file path
  • sample_video_path: Mock video file path
  • mock_model_weights: Mock model weights file
  • environment_setup: Test environment variables
  • mock_dataset_config: Mock dataset configuration
  • mock_training_args: Mock training arguments
  • cleanup_cuda_cache: Automatic CUDA cache cleanup

Development Commands

Both commands work identically and run the full test suite:

poetry run test
poetry run tests

Additional Updates

  • Updated .gitignore with testing-related entries and .claude/*
  • Created validation tests to verify the infrastructure works correctly

How to Use

  1. Install dependencies:

    poetry install
  2. Run tests:

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

    poetry run pytest -m unit       # Run only unit tests
    poetry run pytest -m integration # Run only integration tests
    poetry run pytest -m slow       # Run only slow tests
  4. View coverage report:

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

Notes

  1. Coverage Threshold: Currently set to 0% to allow infrastructure setup to pass. When you start adding actual tests, update these values in pyproject.toml:

    • Line 56: Change --cov-fail-under=0 to --cov-fail-under=80
    • Line 87: Change fail_under = 0 to fail_under = 80
  2. Decord Package: The decord package is temporarily commented out in dependencies due to installation issues. It may need platform-specific installation or alternative packaging.

  3. Poetry Lock File: The poetry.lock file is NOT gitignored and should be committed to ensure reproducible builds.

Next Steps

The testing infrastructure is now ready. Developers can:

  1. Start writing unit tests in tests/unit/
  2. Add integration tests in tests/integration/
  3. Use the provided fixtures for common testing scenarios
  4. Update coverage threshold to 80% once tests are added

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting (HTML/XML) and custom markers
- Create proper test directory structure (unit/integration)
- Add comprehensive test fixtures in conftest.py
- Update .gitignore with testing and Claude-specific entries
- Create validation tests to verify infrastructure setup
- Configure Poetry scripts for 'test' and 'tests' commands

Note: Coverage threshold temporarily set to 0% for infrastructure setup.
Should be changed to 80% when implementing actual tests.
Decord package temporarily commented out due to installation issues.
@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