Skip to content

Conversation

@llbbl
Copy link

@llbbl llbbl commented Jun 25, 2025

Set Up Python Testing Infrastructure

Summary

This PR establishes a comprehensive testing infrastructure for the Intel Neural Compute Application Zoo (ncappzoo) project using Poetry as the package manager and pytest as the testing framework.

Changes Made

Package Management

  • Poetry Configuration: Added pyproject.toml with Poetry configuration as the default package manager
  • Testing Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies

Testing Structure

  • Created organized test directory structure:
    tests/
    ├── __init__.py
    ├── conftest.py
    ├── unit/
    │   └── __init__.py
    └── integration/
        └── __init__.py
    

Pytest Configuration

  • Test Discovery: Configured to find tests matching test_*.py or *_test.py patterns
  • Coverage Settings:
    • Tracks coverage for apps/, networks/, and shared/ directories
    • Generates HTML and XML coverage reports
    • Currently set to 0% threshold (should be updated to 80% once source code is added)
  • Test Markers: Added unit, integration, and slow markers for test categorization
  • Strict Mode: Enabled strict marker validation and verbose output

Shared Fixtures (conftest.py)

Created comprehensive pytest fixtures for common testing scenarios:

  • temp_dir: Temporary directory management
  • sample_image_path: Mock image data for vision tests
  • mock_model_config: Neural network configuration mocking
  • mock_ncs_device: Intel NCS device mocking
  • sample_graph_file: Compiled model graph mocking
  • env_backup: Environment variable preservation
  • mock_openvino_env: OpenVINO environment setup
  • sample_inference_result: Mock inference outputs
  • reset_modules: Module state cleanup between tests
  • capture_stdout: Print statement capture for testing

Additional Updates

  • Updated .gitignore: Added entries for testing artifacts, Poetry files, and Claude configuration
  • Created validation tests: Comprehensive tests to verify the infrastructure setup
  • Updated CLAUDE.md: Documented test commands and infrastructure details

Running Tests

After pulling this branch, install dependencies and run tests:

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

# Install project dependencies
poetry install

# Run all tests
poetry run test

# Alternative command (both work)
poetry run tests

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

# Run with specific coverage report
poetry run pytest --cov-report=html

Notes for Developers

  1. Coverage Threshold: Currently set to 0% since no source code exists yet. Should be updated to 80% once actual code is added.

  2. Test Organization:

    • Place unit tests in tests/unit/
    • Place integration tests in tests/integration/
    • Use appropriate markers (@pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow)
  3. Fixtures: Common fixtures are available in conftest.py. These cover most testing scenarios for this AI/computer vision project.

  4. Poetry Scripts: Both poetry run test and poetry run tests are configured to run pytest with all configured options.

Next Steps

  1. Developers can now immediately start writing tests for existing code
  2. Update coverage threshold to 80% once source code is added
  3. Consider adding additional testing tools like mypy for type checking or ruff for linting
  4. Set up CI/CD to run tests automatically on pull requests

Validation

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

  • All testing dependencies are properly installed
  • Directory structure is correctly created
  • Pytest configuration is working
  • All fixtures function as expected
  • Test markers are properly configured
  • Coverage reporting is set up correctly

All validation tests pass successfully! ✅

- Add Poetry package manager configuration with pytest, pytest-cov, and pytest-mock
- Create test directory structure with unit and integration subdirectories
- Configure pytest with coverage reporting, test markers, and custom settings
- Add comprehensive pytest fixtures for common testing scenarios
- Update .gitignore with testing and Claude-specific entries
- Create validation tests to ensure infrastructure works correctly
- Configure Poetry scripts for running tests with 'poetry run test' or 'poetry run tests'
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