feat: Set up comprehensive Python testing infrastructure with Poetry
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.tomlwith 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_*.pyor*_test.pypatterns - Coverage Settings:
- Tracks coverage for
apps/,networks/, andshared/directories - Generates HTML and XML coverage reports
- Currently set to 0% threshold (should be updated to 80% once source code is added)
- Tracks coverage for
- Test Markers: Added
unit,integration, andslowmarkers 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 managementsample_image_path: Mock image data for vision testsmock_model_config: Neural network configuration mockingmock_ncs_device: Intel NCS device mockingsample_graph_file: Compiled model graph mockingenv_backup: Environment variable preservationmock_openvino_env: OpenVINO environment setupsample_inference_result: Mock inference outputsreset_modules: Module state cleanup between testscapture_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
-
Coverage Threshold: Currently set to 0% since no source code exists yet. Should be updated to 80% once actual code is added.
-
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)
- Place unit tests in
-
Fixtures: Common fixtures are available in
conftest.py. These cover most testing scenarios for this AI/computer vision project. -
Poetry Scripts: Both
poetry run testandpoetry run testsare configured to run pytest with all configured options.
Next Steps
- Developers can now immediately start writing tests for existing code
- Update coverage threshold to 80% once source code is added
- Consider adding additional testing tools like mypy for type checking or ruff for linting
- 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! ✅