Skip to content

feat: Set up comprehensive Python testing infrastructure#7

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

feat: Set up comprehensive Python testing infrastructure#7
llbbl wants to merge 1 commit into
bytedance:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Sep 2, 2025

Set up Python Testing Infrastructure

Summary

This PR establishes a complete testing infrastructure for the RealCustom project, providing developers with a ready-to-use testing environment for writing and running tests.

Changes Made

Package Management

  • Poetry Configuration: Set up pyproject.toml with Poetry as the package manager
  • Dependency Migration: Migrated all dependencies from envs/requirements.txt to Poetry format
  • Development Dependencies: Added testing framework dependencies:
    • pytest ^7.0.0 (main testing framework)
    • pytest-cov ^4.0.0 (coverage reporting)
    • pytest-mock ^3.10.0 (mocking utilities)

Testing Configuration

  • pytest Settings: Configured comprehensive pytest options in pyproject.toml
    • Test discovery patterns for automatic test detection
    • Custom markers: unit, integration, slow
    • Strict configuration for better error reporting
  • Coverage Configuration:
    • 80% coverage threshold requirement
    • HTML and XML report generation
    • Source code inclusion/exclusion rules
    • Coverage for models/, inference/, and schedulers/ directories

Directory Structure

tests/
├── __init__.py
├── conftest.py              # Shared fixtures and test utilities
├── test_infrastructure.py   # Validation tests for infrastructure
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures & Utilities

Created comprehensive fixtures in conftest.py:

  • File System: temp_dir, temp_file, cleanup_files
  • Configuration: sample_config, mock_config_file
  • Testing Data: sample_tensor, sample_image_batch, sample_text_prompts
  • Mock Objects: mock_model, mock_optimizer, mock_scheduler, mock_tokenizer
  • Framework Mocks: mock_torch_device, mock_huggingface_model, mock_gradio_interface
  • Utilities: set_random_seeds, mock_logger

Development Commands

  • poetry run test - Run all tests
  • poetry run tests - Alternative test command
  • Standard pytest options available: -v, -k, -m, --cov, etc.

Infrastructure Validation

  • Validation Tests: Created test_infrastructure.py with 14 tests covering:
    • Python version compatibility
    • Project structure validation
    • Testing dependencies availability
    • Directory structure verification
    • Fixture functionality testing
    • Marker system validation
    • Coverage reporting functionality

Configuration Updates

  • Updated .gitignore: Added .claude/ directory for Claude Code settings
  • Poetry Scripts: Configured commands for easy test execution

Instructions for Running Tests

Basic Usage

# Install dependencies
poetry install

# Run all tests
poetry run test

# Run with verbose output
poetry run test -v

# Run specific test markers
poetry run test -m unit
poetry run test -m integration
poetry run test -m slow

# Run with coverage report
poetry run test --cov=models --cov=inference --cov=schedulers --cov-report=html

Coverage Reports

Coverage reports will be generated in:

  • Terminal: --cov-report=term-missing
  • HTML: htmlcov/index.html (with --cov-report=html)
  • XML: coverage.xml (with --cov-report=xml)

Writing Tests

  • Unit tests: Place in tests/unit/
  • Integration tests: Place in tests/integration/
  • Use fixtures: Import from conftest.py or create test-specific ones
  • Mark tests: Use @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow

Validation Results

All infrastructure validation tests pass:

  • ✅ pytest working correctly
  • ✅ Python 3.8+ compatibility
  • ✅ Project structure exists
  • ✅ Testing directories properly set up
  • ✅ Testing dependencies importable
  • ✅ Fixtures available and functional
  • ✅ Custom markers working
  • ✅ Coverage reporting functional
  • ✅ Mock functionality working

Next Steps

Developers can now:

  1. Start writing unit tests for individual components
  2. Add integration tests for end-to-end workflows
  3. Set up CI/CD pipelines using the established test commands
  4. Extend fixtures in conftest.py for specific testing needs
  5. Configure coverage thresholds per component if needed

The testing infrastructure is ready for immediate use and provides a solid foundation for maintaining code quality in the RealCustom project.

- Configure Poetry as package manager with pyproject.toml
- Migrate dependencies from envs/requirements.txt
- Add pytest, pytest-cov, pytest-mock as development dependencies
- Create testing directory structure (tests/, unit/, integration/)
- Configure pytest with coverage reporting (80% threshold)
- Add custom test markers (unit, integration, slow)
- Create comprehensive shared fixtures in conftest.py
- Set up poetry scripts for running tests (test/tests commands)
- Update .gitignore with testing-related entries
- Add infrastructure validation tests to verify setup
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