Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 23, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the PaddleOCR2Pytorch project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Added pyproject.toml with complete project metadata and dependencies
  • Development Dependencies: Included testing tools (pytest, pytest-cov, pytest-mock) and code quality tools (black, isort, flake8, mypy)
  • Script Commands: Configured poetry run test and poetry run tests commands for easy test execution

Testing Framework

  • pytest Configuration:
    • Configured test discovery patterns for test_*.py and *_test.py files
    • Set up strict markers and configuration options
    • Added custom markers: unit, integration, and slow
    • Configured coverage reporting with 80% threshold requirement

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared fixtures and configuration
├── unit/               # Unit tests directory
│   └── __init__.py
├── integration/        # Integration tests directory
│   └── __init__.py
└── test_setup_validation.py  # Validation tests

Testing Fixtures (conftest.py)

  • temp_dir: Temporary directory management
  • sample_image: Test image generation
  • sample_numpy_image: NumPy array image fixtures
  • sample_tensor_image: PyTorch tensor fixtures
  • mock_config: Configuration dictionary fixtures
  • mock_yaml_config: YAML configuration file fixtures
  • mock_model_path: Model file path fixtures
  • Various OCR-specific fixtures for testing

Coverage Configuration

  • Source directories: pytorchocr, ptstructure, converter, misc, tools
  • Output formats: Terminal, HTML (htmlcov/), XML (coverage.xml)
  • Coverage threshold: 80% (enforced)
  • Branch coverage enabled

Code Quality Tools

  • Black: Code formatting (line length: 120)
  • isort: Import sorting (compatible with Black)
  • flake8: Linting
  • mypy: Type checking

Updated .gitignore

Added entries for:

  • Testing artifacts (.coverage, htmlcov/, pytest_cache/)
  • Claude-specific files (.claude/*)
  • Poetry lock file (poetry.lock)
  • IDE and temporary files

How to Use

Installation

# Install all dependencies including dev dependencies
poetry install --with dev

Running Tests

# Run all tests with coverage
poetry run test

# Alternative command
poetry run tests

# Run specific test file
poetry run pytest tests/test_setup_validation.py

# Run tests with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"

# Run tests in parallel
poetry run pytest -n auto

Coverage Reports

# Generate HTML coverage report
poetry run pytest --cov-report=html

# View coverage in terminal
poetry run pytest --cov-report=term-missing

Validation

The setup includes validation tests (test_setup_validation.py) that verify:

  • All testing dependencies are properly installed
  • Project structure is correctly set up
  • Fixtures are working as expected
  • Custom markers are registered
  • Coverage is configured correctly

All validation tests pass successfully.

Notes

  • The testing infrastructure is ready for immediate use
  • Developers can start writing unit and integration tests in the respective directories
  • The 80% coverage threshold will be enforced on all test runs
  • Both poetry run test and poetry run tests commands are available for flexibility

- Add Poetry package management with pyproject.toml configuration
- Configure pytest with coverage, markers, and custom settings
- Add testing dependencies: pytest, pytest-cov, pytest-mock
- Create test directory structure with unit/integration separation
- Add comprehensive pytest fixtures in conftest.py
- Update .gitignore with testing and Claude-specific entries
- Add validation tests to verify infrastructure setup
- Configure 80% coverage threshold with HTML/XML reporting
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