graphtransformer
graphtransformer 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 Graph Transformer project. While the project uses Conda for its main dependencies, I've added Poetry alongside it specifically for managing testing and development tools, providing a modern Python testing environment.
Changes Made
Package Management
- Added
pyproject.tomlwith Poetry configuration - Configured Poetry to work alongside the existing Conda environment setup
- Note: DGL and other conda-specific packages remain managed by Conda
Testing Dependencies
- pytest: Main testing framework
- pytest-cov: Coverage reporting with 80% threshold
- pytest-mock: Mocking utilities for unit tests
Testing Configuration
- Configured pytest settings in
pyproject.toml:- Test discovery patterns for
test_*.pyand*_test.py - Coverage reporting (terminal, HTML, XML)
- Custom markers:
unit,integration,slow - Strict mode with detailed output
- Coverage fail threshold set to 80%
- Test discovery patterns for
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_setup_validation.py # Validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Shared Fixtures (conftest.py)
temp_dir: Temporary directory managementmock_config: Configuration dictionary for testssample_graph_data: Graph data structures for testingsample_molecular_data: Molecular data for testingmock_model: PyTorch model mockmock_dataloader: DataLoader mocksample_checkpoint: Model checkpoint fixturedevice: CPU device for consistent testingrandom_seed: Reproducible random seedscleanup_cuda: Automatic CUDA cache cleanupmock_tensorboard_writer: TensorBoard writer mock
Development Tools
- Added linting (flake8), formatting (black), type checking (mypy)
- Updated
.gitignorewith testing artifacts and build files - Added Poetry lock file to gitignore (as requested)
How to Use
Initial Setup
# Install Poetry if not already installed
curl -sSL https://install.python-poetry.org | python3 -
# Install testing dependencies
poetry install
# For the main project dependencies, continue using Conda:
conda env create -f environment_cpu.yml # or environment_gpu.yml
Running Tests
# Run all tests
poetry run test
# or
poetry run tests
# Run with specific markers
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m "not slow"
# Run with coverage report
poetry run pytest --cov-report=html
Writing Tests
- Place unit tests in
tests/unit/ - Place integration tests in
tests/integration/ - Use the provided fixtures from
conftest.py - Mark tests appropriately with
@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow
Notes
- The project maintains its original Conda-based dependency management for scientific packages
- Poetry is used specifically for testing and development tools
- DGL (Deep Graph Library) must still be installed via Conda as it's not available on PyPI
- The validation test file (
test_setup_validation.py) verifies the testing setup works correctly
Next Steps
Developers can now immediately start writing tests for the codebase using this infrastructure. The 80% coverage threshold will help maintain code quality as the project evolves.