Radiata icon indicating copy to clipboard operation
Radiata copied to clipboard

feat: Set up comprehensive Python testing infrastructure with Poetry

Open llbbl opened this issue 6 months ago • 3 comments

Set Up Python Testing Infrastructure

Summary

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

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with complete Poetry setup
  • Dependency Migration: Migrated all dependencies from requirements/*.txt files to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Framework Setup

  • Pytest Configuration:

    • Configured test discovery patterns for test_*.py and *_test.py files
    • Set up coverage reporting with HTML and XML output formats
    • Added strict markers and verbose output for better test visibility
    • Configured coverage to track api, lib, and modules directories
  • Test Markers: Added custom markers for test organization:

    • @pytest.mark.unit - For unit tests
    • @pytest.mark.integration - For integration tests
    • @pytest.mark.slow - For slow-running tests

Directory Structure

tests/
├── __init__.py
├── conftest.py          # Shared pytest fixtures
├── test_setup_validation.py  # Validation tests
├── unit/
│   └── __init__.py
└── integration/
    └── __init__.py

Shared Fixtures (conftest.py)

Created comprehensive fixtures for common testing needs:

  • temp_dir - Temporary directory management
  • mock_config - Mock configuration dictionaries
  • mock_model - Mock diffusion models
  • sample_image_path - Test image generation
  • mock_gradio_interface - Mock Gradio interfaces
  • env_vars - Environment variable management
  • mock_torch - Mock PyTorch for CPU-only tests
  • mock_pipeline - Mock diffusion pipelines
  • capture_logs - Log capturing during tests

Configuration Files

  • pyproject.toml: Complete Poetry and testing configuration
  • .gitignore: Updated to exclude testing artifacts while keeping poetry.lock

Running Tests

Install Dependencies

poetry install --with dev

Run Tests

You can run tests using either command:

poetry run test
# or
poetry run tests

Run Specific Test Markers

# Run only unit tests
poetry run pytest -m unit

# Run only integration tests  
poetry run pytest -m integration

# Exclude slow tests
poetry run pytest -m "not slow"

Coverage Reports

  • Terminal: Coverage summary is displayed after each test run
  • HTML Report: Open htmlcov/index.html in a browser
  • XML Report: Available at coverage.xml for CI integration

Notes

  • Coverage Threshold: Currently set to 0% to allow initial setup. Should be increased to 80% as tests are added to the codebase.
  • Poetry Lock File: The poetry.lock file should be committed to ensure reproducible builds.
  • No Production Tests: This PR only sets up the infrastructure. Actual unit tests for the codebase should be added in subsequent PRs.

Validation

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

  • Project structure exists correctly
  • Configuration files are properly set up
  • All fixtures are functional
  • Test markers work as expected
  • Coverage reporting is configured
  • Poetry scripts are available

All validation tests pass successfully, confirming the infrastructure is ready for use.

llbbl avatar Jun 17 '25 00:06 llbbl

The name of this project is not Stable Diffusion WebUI Forge, but Radiata.

fa0311 avatar Jun 17 '25 00:06 fa0311

Oops, you are absolutely right. Thank you so much for catching that!

It looks like a cached project name from a previous run slipped into the PR description. Will get it fixed.

llbbl avatar Jun 17 '25 12:06 llbbl

Hmm. Or maybe it was something else. Anyways, I updated the pull request description and I fixed The poetry files. There was some security issues with some of the older packages. So everything's happy now with Python 3.11. We'll be ready to add actual tests after this is merged now.

llbbl avatar Jun 17 '25 14:06 llbbl