BMW-TensorFlow-Training-GUI
BMW-TensorFlow-Training-GUI copied to clipboard
feat: Add comprehensive Python testing infrastructure with Poetry
Add Python Testing Infrastructure
Summary
This PR sets up a comprehensive testing infrastructure for the BMW LabelTool Lite project using Poetry as the package manager and pytest as the testing framework.
Changes Made
Package Management
- Poetry Setup: Created
pyproject.tomlwith Poetry configuration as the project's package manager - Dependencies: Added testing dependencies as development dependencies:
pytest ^7.4.4- Main testing frameworkpytest-cov ^4.1.0- Coverage reporting pluginpytest-mock ^3.12.0- Mocking utilities
Testing Configuration
-
Pytest Configuration: Configured in
pyproject.tomlwith:- Automatic test discovery patterns
- Coverage settings with 80% threshold
- HTML and XML coverage report generation
- Custom markers:
unit,integration,slow - Strict mode enabled for better error detection
-
Coverage Configuration: Set up comprehensive coverage tracking:
- Covers all three main modules:
docker_sdk_api,inference_api,training_api - Excludes test files, cache, and virtual environments from coverage
- Configured multiple report formats (terminal, HTML, XML)
- Covers all three main modules:
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared pytest fixtures
├── test_infrastructure_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
Created comprehensive fixtures for common testing needs:
temp_dir- Temporary directory managementmock_config- Configuration mockingmock_logger- Logger mockingsample_image_path,sample_model_path- File fixturesmock_request,mock_response- HTTP mockingsample_training_data,sample_inference_data- Data fixturesmock_docker_client- Docker client mocking- Additional fixtures for database, async operations, and file uploads
Development Commands
Configured Poetry scripts for running tests:
poetry run test # Run all tests
poetry run tests # Alternative command (both work)
All standard pytest options are available (e.g., -v, -k, -m, --no-cov)
Additional Setup
-
Updated .gitignore: Added comprehensive Python-specific entries including:
- Testing artifacts (
.pytest_cache/,coverage.xml,htmlcov/) - Claude-specific entries (
.claude/*) - Virtual environments and IDE files
- ML/AI specific files and directories
- Testing artifacts (
-
Validation Tests: Created
test_infrastructure_validation.pyto verify:- All directories and configuration files exist
- Fixtures are properly available
- Markers work correctly
- Coverage is configured properly
How to Use
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 - -
Install dependencies:
poetry install -
Run tests:
poetry run test # Run all tests with coverage poetry run test -v # Verbose output poetry run test -m unit # Run only unit tests poetry run test -m "not slow" # Skip slow tests poetry run test --no-cov # Run without coverage -
View coverage reports:
- Terminal: Shown automatically after test run
- HTML: Open
htmlcov/index.htmlin a browser - XML: Available at
coverage.xmlfor CI integration
Notes
- The project uses Python 3.9+ due to dependency requirements
- Coverage threshold is set to 80% - tests will fail if coverage drops below this
- The infrastructure is ready for immediate test writing - no actual unit tests for the codebase were created
- Each microservice (docker_sdk_api, inference_api, training_api) is included in coverage tracking
- Poetry lock file (
poetry.lock) should be committed to ensure reproducible builds