Skip to content

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 26, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Python project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing and running tests with proper configuration, fixtures, and coverage reporting.

Changes Made

Package Management

  • Poetry Configuration: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated dependencies from requirements.txt to Poetry
  • Test Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies
  • Note: Temporarily commented out vllm dependency due to system build requirements

Testing Configuration

  • pytest Configuration: Configured pytest in pyproject.toml with:
    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML, XML, and terminal output
    • Custom markers for unit, integration, and slow tests
    • Strict marker enforcement and verbose output
    • Coverage threshold of 80% (currently commented out until actual tests are written)

Directory Structure

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

Testing Fixtures (conftest.py)

Created comprehensive shared fixtures including:

  • temp_dir and temp_file - Temporary file system resources
  • mock_config - Mock configuration dictionary
  • sample_json_data and json_file - JSON test data
  • mock_api_client - Mock API client with common HTTP methods
  • mock_llm_response - Mock LLM response structure
  • mock_search_results - Mock search results
  • env_vars - Environment variable management
  • mock_file_system - Mock directory structure
  • capture_logs - Log capture for testing
  • benchmark_timer - Simple performance timing

Project Configuration

  • .gitignore: Created comprehensive gitignore with Python, testing, and IDE-related entries
  • CLAUDE.md: Updated with testing commands and project structure documentation

Validation

  • Created test_infrastructure_validation.py with 18 tests to verify:
    • All fixtures work correctly
    • pytest markers are properly configured
    • Coverage reporting is functional
    • pytest-mock integration works
    • Test discovery functions properly

How to Use

Installation

# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -

# Install dependencies
poetry install

Running Tests

# Run all tests
poetry run test
# or
poetry run tests

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

# Run unit tests only
poetry run pytest -m unit

# Run integration tests only  
poetry run pytest -m integration

# Run without slow tests
poetry run pytest -m "not slow"

# Run with coverage report
poetry run pytest --cov

# Run specific test
poetry run pytest tests/path/to/test.py::TestClass::test_method

Adding New Tests

  1. Create test files in tests/unit/ or tests/integration/
  2. Use fixtures from conftest.py for common test needs
  3. Mark tests appropriately with @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow
  4. Follow the naming convention test_*.py for test files

Notes

  • The coverage threshold is currently commented out since no application code is being tested yet
  • When writing actual tests, uncomment the --cov-fail-under=80 line in pyproject.toml
  • The vllm dependency requires specific system configurations and may need to be installed separately
  • All test dependencies are installed as development dependencies to keep production installations lean

Next Steps

  1. Write unit tests for existing modules in scripts/ and demo/
  2. Add integration tests for end-to-end workflows
  3. Set up CI/CD pipeline to run tests automatically
  4. Configure pre-commit hooks to run tests before commits
  5. Add type checking with mypy or similar tools

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting and custom markers
- Create tests/ directory structure with unit and integration subdirs
- Add comprehensive shared fixtures in conftest.py
- Create .gitignore with Python and testing-related entries
- Add validation tests to verify infrastructure works correctly
- Update CLAUDE.md with testing commands and project structure

Note: vllm dependency commented out due to system requirements
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