Skip to content

feat: Set up comprehensive Python testing infrastructure#19

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

feat: Set up comprehensive Python testing infrastructure#19
llbbl wants to merge 1 commit intoAI4Bharat:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Sep 1, 2025

Set Up Complete Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the IndicCrop project, providing a robust foundation for test-driven development and continuous integration.

Changes Made

Package Management & Dependencies

  • Created pyproject.toml with Poetry configuration
  • Migrated all dependencies from requirements.txt to Poetry format with flexible version constraints
  • Added testing dependencies: pytest, pytest-cov, pytest-mock as development dependencies
  • Configured Poetry scripts: Both poetry run test and poetry run tests commands available

Testing Configuration

  • Comprehensive pytest configuration in pyproject.toml:
    • Test discovery patterns for test_*.py and *_test.py
    • Coverage reporting with 80% threshold
    • HTML and XML coverage report generation
    • Custom markers: unit, integration, slow
    • Strict configuration options for better test reliability

Coverage Configuration

  • Source tracking for the entire project
  • Smart exclusions for test files, virtual environments, build artifacts
  • Multiple report formats: terminal, HTML (htmlcov/), XML (coverage.xml)
  • Configured thresholds and missing line reporting

Directory Structure

  • Created testing directories:
    tests/
    ├── __init__.py
    ├── conftest.py
    ├── unit/
    │   └── __init__.py
    ├── integration/
    │   └── __init__.py
    └── test_setup_validation.py
    

Test Fixtures & Utilities

  • Comprehensive conftest.py with shared fixtures:
    • temp_dir: Temporary directory management
    • sample_config: Mock configuration data
    • mock_transformers_model: Mocked transformer models
    • mock_tokenizer: Mocked tokenizer functionality
    • sample_text_data: Multilingual sample data
    • sample_dataset_dict: Dataset structure fixtures
    • reset_random_seeds: Reproducible test runs
    • And more utilities for testing ML/NLP workflows

Validation & Quality Assurance

  • Created validation test suite (test_setup_validation.py):
    • Infrastructure verification tests
    • Python version compatibility checks
    • Project structure validation
    • Fixture functionality verification
    • Custom marker testing
    • Mock utility validation

Additional Improvements

  • Updated .gitignore with Claude Code settings (.claude/*)
  • Preserved existing entries while adding testing infrastructure exclusions

How to Run Tests

Basic Testing

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

# Run with verbose output
poetry run pytest -v

# Run without coverage (for faster development)
poetry run pytest --no-cov

Marker-Based Testing

# Run only unit tests
poetry run pytest -m "unit"

# Run only integration tests  
poetry run pytest -m "integration"

# Skip slow tests
poetry run pytest -m "not slow"

Coverage Reporting

# Generate HTML coverage report
poetry run pytest --cov-report=html

# View coverage in terminal
poetry run pytest --cov-report=term-missing

Validation Results

All validation tests pass successfully:

  • ✅ 12/12 tests passing
  • ✅ Custom markers (unit, integration, slow) working correctly
  • ✅ Shared fixtures available and functional
  • ✅ Project structure properly configured
  • ✅ Mock utilities ready for ML/NLP testing

Next Steps

The testing infrastructure is now ready for development. Developers can:

  1. Start writing unit tests in tests/unit/
  2. Add integration tests in tests/integration/
  3. Use existing fixtures from conftest.py for common testing patterns
  4. Leverage markers to organize and filter test execution
  5. Monitor coverage to ensure comprehensive testing

Notes

  • Poetry configuration uses flexible version constraints (^x.y.z) for better dependency resolution
  • Coverage configuration excludes test files themselves to focus on source code coverage
  • All standard pytest plugins and markers are available for advanced testing scenarios
  • The infrastructure supports both synchronous and asynchronous testing patterns

- Add Poetry configuration with migrated dependencies from requirements.txt
- Configure pytest with coverage reporting, custom markers, and strict options
- Create testing directory structure with unit/integration subdirectories
- Add comprehensive conftest.py with shared fixtures for testing
- Include validation tests to verify testing infrastructure functionality
- Update .gitignore with Claude Code settings
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