Skip to content

feat: Add comprehensive Python testing infrastructure with Poetry #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

llbbl
Copy link

@llbbl llbbl commented Jun 20, 2025

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.toml with 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_*.py and *_test.py
    • Coverage reporting (terminal, HTML, XML)
    • Custom markers: unit, integration, slow
    • Strict mode with detailed output
    • Coverage fail threshold set to 80%

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 management
  • mock_config: Configuration dictionary for tests
  • sample_graph_data: Graph data structures for testing
  • sample_molecular_data: Molecular data for testing
  • mock_model: PyTorch model mock
  • mock_dataloader: DataLoader mock
  • sample_checkpoint: Model checkpoint fixture
  • device: CPU device for consistent testing
  • random_seed: Reproducible random seeds
  • cleanup_cuda: Automatic CUDA cache cleanup
  • mock_tensorboard_writer: TensorBoard writer mock

Development Tools

  • Added linting (flake8), formatting (black), type checking (mypy)
  • Updated .gitignore with 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

  1. Place unit tests in tests/unit/
  2. Place integration tests in tests/integration/
  3. Use the provided fixtures from conftest.py
  4. 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.

- Set up Poetry for dependency management alongside existing Conda setup
- Add pytest, pytest-cov, and pytest-mock as development dependencies
- Configure pytest with coverage thresholds (80%) and custom markers
- Create test directory structure with unit/integration subdirectories
- Add comprehensive shared fixtures in conftest.py for common test needs
- Update .gitignore with testing artifacts and Claude-specific entries
- Add Poetry script commands for running tests (poetry run test/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