Skip to content

feat: Set up comprehensive Python testing infrastructure#40

Open
llbbl wants to merge 1 commit into
midrender:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Set up comprehensive Python testing infrastructure#40
llbbl wants to merge 1 commit into
midrender:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 25, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the Mamba Chat project, providing developers with a ready-to-use testing environment that follows Python best practices.

Changes Made

Package Management

  • Added Poetry as the package manager for development dependencies
  • Created pyproject.toml with full Poetry configuration
  • Kept production dependencies in requirements.txt (as they have CUDA-specific requirements)

Testing Framework

  • Configured pytest as the main testing framework
  • Added pytest-cov for code coverage reporting
  • Added pytest-mock for mocking utilities
  • Set up 80% coverage threshold with HTML and XML reporting

Configuration

  • Test Discovery: Configured to find tests matching test_*.py or *_test.py patterns
  • Coverage Settings:
    • Source tracking for the project
    • Exclusions for test files, virtual environments, and boilerplate code
    • Multiple report formats (terminal, HTML, XML)
  • Custom Markers:
    • @pytest.mark.unit - Fast, isolated unit tests
    • @pytest.mark.integration - Tests requiring external resources
    • @pytest.mark.slow - Long-running tests (skipped by default)

Directory Structure

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

Fixtures

Created comprehensive fixtures in conftest.py:

  • temp_dir - Temporary directory for test files
  • temp_file - Helper to create temporary files
  • mock_config - Mock configuration object
  • mock_model - Mock ML model
  • mock_tokenizer - Mock tokenizer
  • mock_dataset - Mock dataset
  • isolated_filesystem - Run tests in isolated directory
  • capture_logs - Capture log output during tests

Additional Setup

  • Updated .gitignore with testing artifacts and Claude-specific entries
  • Created validation tests to ensure the infrastructure works correctly
  • Added support for --runslow flag to run slow tests

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests
poetry run pytest

# Run with coverage report
poetry run pytest --cov

# Run without coverage
poetry run pytest --no-cov

# Run only unit tests
poetry run pytest -m unit

# Run integration tests
poetry run pytest -m integration

# Include slow tests
poetry run pytest --runslow

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

View Coverage Reports

  • Terminal: Shown automatically when running tests
  • HTML: Open htmlcov/index.html in your browser
  • XML: Available at coverage.xml for CI integration

Notes

  1. Production Dependencies: The main project dependencies (torch, transformers, etc.) remain in requirements.txt due to their CUDA-specific requirements. This testing infrastructure is focused on development dependencies only.

  2. Coverage Threshold: Set to 80% by default. Tests will fail if coverage drops below this threshold.

  3. Slow Tests: Tests marked with @pytest.mark.slow are skipped by default to keep the test suite fast. Use --runslow to include them.

  4. Package Structure: Created a minimal mamba_chat package directory to satisfy Poetry's requirements. The actual project code structure can be organized as needed.

Next Steps

Developers can now immediately start writing tests by:

  1. Creating test files in tests/unit/ or tests/integration/
  2. Using the provided fixtures from conftest.py
  3. Marking tests appropriately with @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow

- Add Poetry as package manager with pyproject.toml configuration
- Configure pytest with coverage reporting (80% threshold)
- Create testing directory structure (tests/unit, tests/integration)
- Add comprehensive pytest fixtures in conftest.py
- Configure test markers (unit, integration, slow)
- Update .gitignore with testing and Claude-specific entries
- 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