Skip to content

feat: Set up comprehensive Python testing infrastructure with Poetry#88

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

feat: Set up comprehensive Python testing infrastructure with Poetry#88
llbbl wants to merge 1 commit into
ahmetozlu:masterfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 27, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the vehicle detection 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 tests.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration
  • Dependency Migration: Migrated existing dependencies from requirements.txt to Poetry
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies

Testing Configuration

  • pytest Configuration:

    • Test discovery patterns for test_*.py and *_test.py files
    • Coverage reporting with HTML and XML output formats
    • Custom markers for unit, integration, and slow tests
    • Strict mode enabled for better error detection
  • Coverage Configuration:

    • Source directories: utils and protos
    • Excluded: test files, cache directories, virtual environments
    • Coverage threshold set to 0% initially (to be increased as tests are added)

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory for test files
  • mock_config: Mock configuration dictionary
  • sample_image_path, sample_video_path: Sample file paths
  • mock_label_map: Object detection label mapping
  • sample_detection_result: Sample detection results
  • mock_model_config: Model configuration file
  • color_training_data: Color recognition training data
  • reset_environment: Environment reset fixture
  • capture_logs: Log capture utility

Development Commands

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

Additional Setup

  • Updated .gitignore with:
    • Testing artifacts (.pytest_cache/, .coverage, htmlcov/, coverage.xml)
    • Claude settings (.claude/*)
    • IDE files (.idea/, .vscode/)
    • Build artifacts and virtual environments
  • Note: poetry.lock is NOT ignored and should be committed

How to Use

  1. Install dependencies:

    poetry install
  2. Run all tests:

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

    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. View coverage report:

    # HTML report generated in htmlcov/
    # Open htmlcov/index.html in a browser

Validation

The infrastructure has been validated with a test suite that verifies:

  • ✅ All directories exist
  • ✅ Fixtures are working correctly
  • ✅ Test markers are configured
  • ✅ Poetry commands work as expected
  • ✅ Coverage reporting generates properly

Next Steps

  1. Increase coverage threshold in pyproject.toml as tests are added
  2. Write unit tests for existing modules
  3. Add integration tests for the vehicle detection pipeline
  4. Configure CI/CD to run tests automatically

Notes

  • The coverage threshold is currently set to 0% to allow the infrastructure to be set up without existing tests. This should be gradually increased as test coverage improves.
  • All test dependencies are isolated as development dependencies and won't be installed in production environments.
  • The testing structure follows pytest best practices with clear separation between unit and integration tests.

- Initialize Poetry package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Configure pytest with coverage reporting and custom markers
- Create tests directory structure with shared fixtures
- Add Poetry script commands for running tests
- Update .gitignore with testing and development 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