Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 25, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a comprehensive testing infrastructure for the TensorFlow-Slim models project, providing developers with all the tools needed to write and run tests effectively.

Changes Made

Package Management

  • Poetry Setup: Configured Poetry as the package manager via pyproject.toml
  • Dependency Migration: Migrated from traditional setup.py to modern Poetry configuration
  • Lock File: Poetry will generate a poetry.lock file for reproducible builds

Testing Dependencies

Added the following development dependencies:

  • pytest ^7.4.0 - Modern Python testing framework
  • pytest-cov ^4.1.0 - Coverage reporting plugin for pytest
  • pytest-mock ^3.11.0 - Mocking utilities for pytest

Testing Configuration

Configured in pyproject.toml:

  • Test Discovery: Configured to find test_*.py and *_test.py files
  • Coverage Settings:
    • 80% minimum coverage threshold
    • HTML, XML, and terminal coverage reports
    • Excludes test files and setup files from coverage
  • Custom Markers: Added unit, integration, and slow markers for test categorization
  • Strict Mode: Enabled strict markers and verbose output

Directory Structure

Created organized testing structure:

tests/
├── __init__.py
├── conftest.py          # Shared pytest fixtures
├── unit/
│   └── __init__.py
├── integration/
│   └── __init__.py
└── test_infrastructure_validation.py

Shared Fixtures (conftest.py)

Comprehensive fixtures for common testing needs:

  • temp_dir - Temporary directory management
  • mock_image_file - Creates test images
  • mock_model_checkpoint - Mock TensorFlow checkpoints
  • mock_tfrecord_file - Mock TFRecord files
  • mock_labels_file - Label file generation
  • mock_config - Configuration dictionaries
  • mock_dataset_split - Dataset directory structures
  • capture_logs - Log capture utilities
  • mock_env_vars - Environment variable mocking
  • cleanup_files - File cleanup tracking
  • Auto-reset of TensorFlow graphs between tests

Development Commands

Configured Poetry scripts for convenience:

  • poetry run test - Run all tests
  • poetry run tests - Alternative command (both work identically)

Both commands support all standard pytest options (e.g., -v, -k, -m, etc.)

Version Control

Added comprehensive .gitignore covering:

  • Python build artifacts and caches
  • Testing outputs (coverage reports, pytest cache)
  • Virtual environments
  • IDE files
  • TensorFlow specific files (checkpoints, events, models)
  • Claude AI settings

Usage Instructions

Initial Setup

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

# Install dependencies
poetry install

# Run validation tests
poetry run test tests/test_infrastructure_validation.py -v

Running Tests

# Run all tests
poetry run test

# Run with coverage report
poetry run test --cov-report=html

# Run specific test markers
poetry run test -m unit
poetry run test -m integration
poetry run test -m "not slow"

# Run specific test file
poetry run test tests/unit/test_example.py

Writing New Tests

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

Notes

  • The infrastructure is ready for immediate use - developers can start writing tests right away
  • Coverage reporting is configured but will show 0% until actual tests are written for the codebase
  • The validation test file demonstrates all fixture usage and can serve as a reference
  • TensorFlow dependencies are included based on the project requirements

Next Steps

  1. Developers can now write unit tests for individual components
  2. Integration tests can be added for end-to-end workflows
  3. Consider adding pre-commit hooks to run tests automatically
  4. Set up CI/CD pipeline to run tests on pull requests

- Set up Poetry as package manager with pyproject.toml configuration
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage reporting (80% threshold)
- Create tests directory structure with shared fixtures in conftest.py
- Add custom pytest markers (unit, integration, slow)
- Configure Poetry scripts for running tests (test/tests commands)
- Add comprehensive .gitignore for Python projects
- Include validation tests to verify infrastructure works correctly
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