Skip to content

feat: Add Python testing infrastructure with Poetry and pytest#128

Open
llbbl wants to merge 1 commit into
NVIDIA-AI-IOT:mainfrom
UnitSeeker:add-testing-infrastructure
Open

feat: Add Python testing infrastructure with Poetry and pytest#128
llbbl wants to merge 1 commit into
NVIDIA-AI-IOT:mainfrom
UnitSeeker:add-testing-infrastructure

Conversation

@llbbl
Copy link
Copy Markdown

@llbbl llbbl commented Jun 29, 2025

Add Python Testing Infrastructure

Summary

This PR sets up a complete Python testing infrastructure for the PointPillar project using Poetry for dependency management and pytest for testing. The setup provides a ready-to-use testing environment where developers can immediately start writing tests.

Changes Made

Package Management

  • Poetry Setup: Created pyproject.toml with Poetry configuration as the primary package manager
  • Dependency Migration: Identified and migrated existing Python dependencies (torch, numpy, onnx, fire, pyyaml)
  • Development Dependencies: Added pytest, pytest-cov, and pytest-mock as development dependencies

Testing Configuration

  • pytest Configuration:

    • Configured test discovery patterns for test_*.py and *_test.py files
    • Added custom markers for unit, integration, and slow tests
    • Set up both pytest.ini and pyproject.toml configurations
  • Coverage Settings:

    • Configured coverage reporting with HTML and XML outputs
    • Set 80% coverage threshold (configurable)
    • Added exclusion patterns for virtual environments and cache files

Directory Structure

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

Shared Fixtures (conftest.py)

  • temp_dir: Temporary directory that auto-cleans after tests
  • sample_point_cloud: Generate sample point cloud data
  • sample_config: Provide test configuration dictionaries
  • mock_model_path: Create mock ONNX model paths
  • sample_bin_file: Create sample binary point cloud files
  • mock_yaml_config: Create YAML configuration files
  • device: Get appropriate torch device (CPU/CUDA)
  • reset_environment: Reset env variables between tests
  • capture_logs: Capture log messages during tests

Additional Files

  • Updated .gitignore: Added comprehensive Python testing entries
  • run_tests_with_coverage.sh: Script for running tests with full coverage reporting

How to Use

Install Dependencies

poetry install

Run Tests

# Run all tests (both commands work)
poetry run test
poetry run tests

# Run tests with coverage reporting
./run_tests_with_coverage.sh

# Run specific test types
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

Writing New Tests

  1. Create test files in tests/unit/ or tests/integration/
  2. Use the provided fixtures from conftest.py
  3. Mark tests appropriately with @pytest.mark.unit, @pytest.mark.integration, or @pytest.mark.slow

Notes

  • onnxsim: Commented out in dependencies as it requires cmake to build. Can be uncommented if cmake is available in the build environment.
  • pcdet: Commented out as it's not available via PyPI. Should be installed separately if needed for the project.
  • Coverage: The infrastructure is set up to measure coverage of the tool directory. Currently, validation tests don't contribute to coverage metrics.
  • Poetry Lock: The poetry.lock file should be committed to ensure reproducible builds across environments.

Validation

The setup includes validation tests that verify:

  • All required imports work correctly
  • Pytest fixtures function as expected
  • File operations in temporary directories
  • NumPy operations on point cloud data
  • Binary file creation and reading
  • YAML configuration handling
  • Parametrized tests
  • Test markers (unit, integration, slow)

All validation tests pass successfully, confirming the testing infrastructure is ready for use.

- Configure Poetry as package manager with pyproject.toml
- Add pytest, pytest-cov, and pytest-mock as dev dependencies
- Set up test directory structure with unit/integration subdirs
- Create comprehensive conftest.py with shared fixtures
- Configure pytest with markers and coverage settings
- Update .gitignore with testing and Poetry entries
- Add validation tests to verify infrastructure works
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