Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 24, 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 ready-to-use environment for developers to immediately start writing and running tests.

Changes Made

Package Management

  • Poetry configured as the package manager via pyproject.toml
  • Migrated existing dependencies (openai) to Poetry
  • Added testing dependencies as development dependencies:
    • pytest (^8.0.0) - Main testing framework
    • pytest-cov (^5.0.0) - Coverage reporting
    • pytest-mock (^3.14.0) - Mocking utilities

Testing Configuration

  • pytest configuration in pyproject.toml with:
    • Strict markers and configuration
    • Coverage reporting with HTML and XML output
    • Coverage threshold set to 15% (adjustable as more tests are added)
    • Test discovery patterns for test_*.py and *_test.py files
    • Custom markers: unit, integration, slow

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir - Temporary directory for file operations
  • mock_openai_client - Mocked OpenAI client
  • sample_questions_file - Sample test data files
  • sample_json_data - JSON test data
  • mock_env_variables - Environment variable mocking
  • mock_file_system - Mock file system structure
  • cleanup_test_artifacts - Automatic test cleanup
  • capture_logs - Log capture utility
  • mock_time - Time function mocking

Code Organization

  • Moved generate.py to src/ directory for better package structure
  • Created src/__init__.py for proper module imports

Development Experience

  • Added Poetry scripts for easy test execution:
    • poetry run test - Run all tests with coverage
    • poetry run tests - Alternative command (both work)
  • Updated .gitignore with:
    • Python artifacts (__pycache__/, *.pyc, etc.)
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/)
    • Poetry artifacts (dist/, build/)
    • IDE files and Claude settings

How to Use

  1. Install dependencies:

    poetry install
  2. Run all tests:

    poetry run test
    # or
    poetry run tests
  3. Run specific test files:

    poetry run pytest tests/test_setup_validation.py
  4. Run tests with specific markers:

    poetry run pytest -m unit        # Run only unit tests
    poetry run pytest -m integration # Run only integration tests
    poetry run pytest -m "not slow"  # Skip slow tests
  5. View coverage report:

    • HTML report: Open htmlcov/index.html in a browser
    • XML report: Available at coverage.xml for CI integration

Notes

  • The coverage threshold is currently set to 15% to allow the infrastructure to be merged. This should be increased as more tests are added.
  • The validation tests confirm that all components of the testing infrastructure are working correctly.
  • All 13 validation tests are passing, confirming the setup is complete and functional.
  • The project is now ready for developers to start writing unit and integration tests for the actual codebase.

- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage reporting (HTML/XML)
- Create test directory structure (unit/integration)
- Add comprehensive test fixtures in conftest.py
- Configure custom pytest markers (unit, integration, slow)
- Set up Poetry scripts for running tests
- Update .gitignore with testing and Poetry artifacts
- Add validation tests to verify infrastructure 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