BGRL_Pytorch
BGRL_Pytorch copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Set up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the BGRL PyTorch project, providing developers with everything needed to start writing and running tests immediately.
Changes Made
Package Management
- Added Poetry configuration via
pyproject.tomlwith project metadata and dependency management - Migrated existing dependencies (torch, numpy, tensorboardX) to Poetry format
- Added testing dependencies as dev dependencies:
pytest(main testing framework)pytest-cov(coverage reporting)pytest-mock(mocking utilities)
Testing Configuration
-
Comprehensive pytest configuration in
pyproject.toml:- Test discovery patterns for files, classes, and functions
- Coverage reporting with 80% threshold requirement
- HTML and XML coverage report generation
- Custom test markers:
unit,integration,slow - Strict configuration for better test reliability
-
Coverage configuration with:
- Source directory inclusion/exclusion rules
- Exclusion of test files, virtual environments, and build artifacts
- Multiple report formats (terminal, HTML, XML)
Directory Structure
- Created testing directory hierarchy:
tests/ ├── __init__.py ├── conftest.py ├── test_infrastructure.py ├── unit/ │ └── __init__.py └── integration/ └── __init__.py
Shared Testing Fixtures
- Comprehensive
conftest.pywith fixtures for:- Temporary directories for test isolation
- Sample graph data generation (nodes, edges, features)
- Mock configurations and command-line arguments
- TensorBoard writer mocking
- Random seed management for reproducible tests
- Mock PyTorch devices and tensor data
Development Scripts
- Poetry script commands:
poetry run test- Run all testspoetry run tests- Alternative command (both work identically)- All standard pytest options available
Infrastructure Files
- Updated
.gitignorewith comprehensive patterns for:- Testing artifacts (
.pytest_cache/,.coverage,htmlcov/) - Python build artifacts and virtual environments
- IDE and OS files
- Model checkpoints and data directories
- Claude Code settings
- Testing artifacts (
Validation
- Created
test_infrastructure.pywith validation tests that verify:- pytest and PyTorch functionality
- All fixtures work correctly
- Test markers function properly
- Random seed reproducibility
- Class-based testing capabilities
Instructions for Running Tests
Initial Setup
# Install dependencies
poetry install
# Run all tests
poetry run test
# Or alternatively
poetry run tests
Test Commands
# Run specific test markers
poetry run pytest -m unit # Unit tests only
poetry run pytest -m integration # Integration tests only
poetry run pytest -m "not slow" # Skip slow tests
# Run with coverage report
poetry run pytest --cov=. --cov-report=html
# Run specific test file
poetry run pytest tests/test_infrastructure.py
# Run with verbose output
poetry run pytest -v
Coverage Reports
- Terminal output: Shows coverage summary after each test run
- HTML report: Generated in
htmlcov/directory - XML report: Generated as
coverage.xmlfor CI integration
Dependencies Added
Production Dependencies
torch ^2.0.0numpy ^1.21.0tensorboardX ^2.4
Development Dependencies
pytest ^7.4.0pytest-cov ^4.1.0pytest-mock ^3.11.0
Notes
- Poetry lock file (
poetry.lock) is included in version control for reproducible builds - Coverage threshold set to 80% - tests will fail if coverage drops below this
- Test isolation ensured through comprehensive fixtures and temporary directories
- Ready for CI/CD - XML coverage reports can be integrated with code quality tools
- Extensible - Easy to add new fixtures and test categories as needed
Validation Results
✅ All 13 validation tests pass
✅ Both poetry run test and poetry run tests commands work
✅ Coverage reporting generates properly (HTML and XML)
✅ All pytest markers function correctly
✅ Fixture isolation and reproducibility verified
The testing infrastructure is now ready for developers to start writing comprehensive tests for the BGRL implementation.