Skip to content

Conversation

@llbbl
Copy link
Contributor

@llbbl llbbl commented Jun 25, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the ModelCache project, migrating from pip/requirements.txt to Poetry for dependency management and setting up pytest as the testing framework.

Changes Made

Package Management Migration

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from requirements.txt to Poetry
  • Added development dependencies: pytest, pytest-cov, pytest-mock
  • Configured Poetry scripts for easy test execution

Testing Configuration

  • pytest configuration in pyproject.toml:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML output
    • 80% coverage threshold (can be adjusted as needed)
    • Strict markers and verbose output
    • Custom markers: unit, integration, slow
  • Coverage configuration:

    • Source includes both modelcache and modelcache_mm packages
    • Excludes test files, cache directories, and virtual environments
    • Detailed reporting with line numbers and branch coverage

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • mock_embedding: Mock embedding object
  • mock_cache_manager: Mock cache manager
  • sample_vector_data: Sample 768-dimensional vector data
  • mock_redis_client: Mock Redis client
  • mock_milvus_client: Mock Milvus client
  • sample_text_data: Sample text data for testing
  • mock_http_response: Mock HTTP response
  • reset_environment: Auto-reset environment variables

Testing Commands

After installing dependencies with poetry install, you can run tests using:

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work)
  • poetry run pytest - Direct pytest execution
  • poetry run pytest -m unit - Run only unit tests
  • poetry run pytest -m integration - Run only integration tests
  • poetry run pytest --cov-report=html - Generate HTML coverage report

Additional Updates

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • Poetry artifacts (excluding poetry.lock which should be committed)
    • IDE and temporary files

How to Use

  1. Install Poetry if not already installed:

    curl -sSL https://install.python-poetry.org | python3 -
  2. Install dependencies:

    poetry install
  3. Run tests:

    poetry run test
  4. View coverage report:

    poetry run pytest --cov-report=html
    open htmlcov/index.html

Notes

  • The validation tests (test_setup_validation.py) verify that the testing infrastructure is properly configured
  • Coverage threshold is set to 80% but will initially fail since no actual tests exist yet
  • All pytest options are available through the Poetry scripts
  • The infrastructure supports both synchronous and asynchronous test patterns
  • Fixtures are designed to be extensible for future test development

Next Steps

With this infrastructure in place, developers can now:

  1. Write unit tests in the tests/unit/ directory
  2. Write integration tests in the tests/integration/ directory
  3. Use the provided fixtures for mocking dependencies
  4. Monitor test coverage to ensure code quality

- Migrated from requirements.txt to Poetry package management
- Added pytest, pytest-cov, and pytest-mock as dev dependencies
- Configured pytest with coverage reporting (80% threshold)
- Created test directory structure with unit/integration folders
- Added comprehensive shared fixtures in conftest.py
- Set up test markers for unit, integration, and slow tests
- Created validation tests to verify infrastructure setup
- Updated .gitignore with testing and Claude-related entries
- Configured Poetry scripts for running tests (test/tests commands)
@peng3307165
Copy link
Collaborator

We have merged your commit into the main branch. Thank you for your contributions to the ModelCache project.
Best wishes!

@peng3307165 peng3307165 merged commit b7e03ec into codefuse-ai:main Jun 30, 2025
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