Skip to content

feat: add complete Python testing infrastructure with Poetry#47

Open
llbbl wants to merge 1 commit intokelvinxu:masterfrom
UnitSeeker:add-testing-infrastructure
Open

feat: add complete Python testing infrastructure with Poetry#47
llbbl wants to merge 1 commit intokelvinxu:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 23, 2025

Add Complete Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the attention-based image caption generation project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration as the primary package manager
  • Dependencies: Migrated existing dependencies (numpy, theano, scikit-learn, etc.) to Poetry
  • Dev Dependencies: Added pytest (^7.4.0), pytest-cov (^4.1.0), and pytest-mock (^3.11.0)

Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns for test_*.py and *_test.py files
    • Added custom test markers: unit, integration, and slow
    • Set up verbose output with strict markers
    • Configured coverage reporting with HTML and XML outputs
  • Coverage Configuration:

    • Source directories configured with appropriate exclusions
    • HTML coverage reports output to htmlcov/
    • XML coverage report outputs to coverage.xml
    • Excluded test files, virtual environments, and cache directories

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)

  • temp_dir: Creates temporary directories for test files
  • mock_config: Provides mock configuration dictionaries
  • sample_image_features: Generates sample image features
  • sample_captions: Provides test captions
  • sample_vocabulary: Creates test vocabularies
  • model_params: Provides sample model parameters
  • mock_data_iterator: Creates mock data iterators
  • Additional utility fixtures for testing

Development Commands

Two equivalent commands are available for running tests:

  • poetry run test
  • poetry run tests

Both commands run pytest with all configured options.

.gitignore Updates

Added entries for:

  • Testing artifacts: .pytest_cache/, .coverage, htmlcov/, coverage.xml
  • Claude settings: .claude/*
  • Virtual environments and IDE files
  • Note: poetry.lock is intentionally NOT ignored (should be committed)

Running Tests

  1. Install dependencies:

    poetry install --with dev
  2. Run all tests:

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

    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
  4. Run without coverage:

    poetry run pytest --no-cov

Validation

The setup has been validated with a test suite (test_setup_validation.py) that verifies:

  • pytest is working correctly
  • All fixtures are accessible
  • Coverage reporting is configured
  • pytest-mock is functional
  • Test directory structure is correct
  • File operations work in temporary directories

All validation tests pass successfully.

Notes

  • Coverage threshold is currently set to 0% due to Python 2 syntax in existing files
  • The infrastructure is ready for developers to start writing tests immediately
  • All testing dependencies are isolated as development dependencies
  • The setup follows Python testing best practices with proper directory structure and configuration

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