REDN
REDN copied to clipboard
feat: Set up comprehensive Python testing infrastructure
Set up Python Testing Infrastructure
This PR establishes a comprehensive testing infrastructure for the OpenNRE project, providing all the necessary tools and configuration for developers to write and run tests effectively.
Summary of Changes
Package Management
-
Added Poetry configuration via
pyproject.tomlwith project metadata and dependencies - Migrated from requirements.txt to Poetry for better dependency management
- Set up development dependencies separately from production dependencies
Testing Framework Setup
-
pytest configuration with comprehensive settings in
pyproject.toml:- Test discovery patterns for files, classes, and functions
- Custom markers:
unit,integration,slow - Coverage reporting with 80% threshold
- Strict configuration and marker enforcement
- Coverage reporting configured for HTML, XML, and terminal output
- Testing dependencies: pytest, pytest-cov, pytest-mock
Directory Structure
-
Created
tests/directory with proper__init__.pyfiles -
Organized test structure:
-
tests/unit/for unit tests -
tests/integration/for integration tests -
tests/conftest.pyfor shared fixtures
-
Shared Testing Fixtures
-
Comprehensive fixtures in
conftest.pyincluding:- Temporary directories and files
- Mock models, encoders, and tokenizers
- Sample data structures for relation extraction
- Configuration and training argument fixtures
- Random seed fixtures for reproducible tests
- AWS credential mocking
- Automatic test environment setup
- Optional dependency handling - fixtures gracefully handle missing numpy/torch
Configuration Files
- Updated .gitignore with testing artifacts, IDE files, and Claude settings
- pyproject.toml includes pytest configuration, coverage settings, and build system
Validation
- Created validation tests to verify the infrastructure setup
- Tested fixture accessibility and pytest functionality
- Verified coverage reporting and custom markers work correctly
Running Tests
After installing dependencies, you can run tests using:
# Install all dependencies
poetry install
# Run all tests with coverage
poetry run pytest
# Run tests with verbose output
poetry run pytest -v
# Run only unit tests
poetry run pytest -m unit
# Run tests excluding slow ones
poetry run pytest -m "not slow"
# Generate coverage reports
poetry run pytest --cov=opennre --cov-report=html
Coverage Reports
The infrastructure generates coverage reports in multiple formats:
- Terminal output with missing lines
-
HTML report in
htmlcov/directory -
XML report as
coverage.xml
Notes
- The testing infrastructure is designed to work with or without ML dependencies (torch, numpy)
- Fixtures will skip tests gracefully if required dependencies are not available
- The 80% coverage threshold can be adjusted in
pyproject.tomlif needed - Additional ML dependencies can be installed later without affecting the testing setup
Dependencies
Development Dependencies Added:
-
pytest ^7.4.0- Main testing framework -
pytest-cov ^4.1.0- Coverage reporting -
pytest-mock ^3.11.0- Mocking utilities
The infrastructure is now ready for developers to start writing comprehensive tests for the OpenNRE codebase.