HNRE
HNRE copied to clipboard
feat: Set up complete Python testing infrastructure with Poetry
Set Up Python Testing Infrastructure
Summary
This PR establishes a complete testing infrastructure for the Neural Relation Extraction project using Poetry as the package manager and pytest as the testing framework. The setup provides a solid foundation for writing unit and integration tests with comprehensive coverage reporting.
Changes Made
Package Management
- Poetry Configuration: Created
pyproject.tomlwith Poetry as the package manager - Dependencies: Migrated project dependencies (tensorflow, numpy, scikit-learn, matplotlib) to Poetry
- Development Dependencies: Added pytest, pytest-cov, and pytest-mock as dev dependencies
Testing Configuration
- pytest Settings: Configured test discovery, coverage thresholds (80%), and output formatting
- Coverage Reports: Set up HTML and XML coverage reporting with branch coverage
- Custom Markers: Added
unit,integration, andslowmarkers for test categorization
Directory Structure
tests/
├── __init__.py
├── conftest.py # Shared fixtures and configuration
├── test_validation.py # Infrastructure validation tests
├── unit/
│ └── __init__.py
└── integration/
└── __init__.py
Test Fixtures (conftest.py)
temp_dir: Temporary directory for test filessample_data_dir: Mock data directory structuremock_config: Configuration dictionary for testingsample_json_config: JSON configuration file fixturemock_tensorflow_session: Mock TensorFlow sessionsample_numpy_data: Sample numpy arraysmock_model: Mock model objectsample_text_data: Sample text datamock_file_system: Mock file system operationscapture_stdout: Stdout capture for testing print statementsmock_time: Time mocking utilities- And more...
Development Support
- Script Commands: Both
poetry run testandpoetry run testswork for running tests - Git Ignore: Updated
.gitignorewith testing artifacts and Poetry files - Validation Tests: Created comprehensive validation tests to verify the infrastructure
How to Use
Installation
# Install all dependencies including dev dependencies
poetry install
Running Tests
# Run all tests
poetry run test
# Alternative command (same as above)
poetry run tests
# Run only unit tests
poetry run pytest -m unit
# Run only integration tests
poetry run pytest -m integration
# Run tests excluding slow ones
poetry run pytest -m "not slow"
# Run with specific verbosity
poetry run pytest -v
# Run specific test file
poetry run pytest tests/test_validation.py
# 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 fixtures from
conftest.pyfor common test needs - Mark tests appropriately with
@pytest.mark.unit,@pytest.mark.integration, or@pytest.mark.slow
Coverage Reports
- Terminal: Coverage shown automatically after test runs
- HTML Report: View detailed coverage at
htmlcov/index.html - XML Report: Available at
coverage.xmlfor CI/CD integration
Notes
- The coverage threshold is set to 80% for both line and branch coverage
- The testing infrastructure is ready for immediate use - developers can start writing tests right away
- All pytest standard options are available through the Poetry commands
- The
poetry.lockfile should be committed to ensure reproducible builds across environments
Next Steps
With this testing infrastructure in place, the team can now:
- Write unit tests for individual components (model, utils, scripts)
- Create integration tests for end-to-end workflows
- Add performance benchmarks using the slow marker
- Integrate with CI/CD pipelines using the XML coverage reports