Add comprehensive testing infrastructure with Poetry and pytest
## About UnitSeeker
Hi! This PR is part of the UnitSeeker project, a human-guided initiative to help Python repositories establish testing infrastructure.
**Key points:**
- **Human-approved**: Every PR is manually approved before work begins
- **Semi-automated with oversight**: Created and controlled via a homegrown wrapper around Claude Code with human quality control
- **Infrastructure only**: This PR intentionally contains only the testing setup without actual unit tests
- **Your repository, your rules**: Feel free to modify, reject, or request changes - all constructive feedback is welcome
- **Follow-up support**: All responses and discussions are personally written, not automated
Learn more about the project and see the stats on our progress at **https://unitseeker.llbbl.com/**
---
## Summary
This PR establishes a comprehensive root-level testing infrastructure for the Infinity monorepo using Poetry and pytest. While the individual packages (`libs/infinity_emb`, `libs/client_infinity`, etc.) already have their own testing setups, this adds a unified testing framework at the repository root level to orchestrate tests across all packages.
## Changes Made
### Package Management
- ✅ Created root-level `pyproject.toml` with Poetry configuration
- ✅ Configured Poetry in `package-mode = false` for monorepo compatibility
- ✅ Added test dependencies: `pytest ^8.0.0`, `pytest-cov ^6.0.0`, `pytest-mock ^3.14.0`
- ✅ Generated `poetry.lock` file (committed for reproducibility)
### Testing Configuration
- ✅ Configured pytest with comprehensive settings in `pyproject.toml`:
- Test discovery patterns for both root and lib-level tests
- Custom markers: `unit`, `integration`, `slow`, `performance`
- Verbose output with strict marker and config enforcement
- Coverage reporting with 80% threshold
- HTML and XML coverage report generation
- ✅ Configured coverage.py with:
- Source directories: `libs/`
- Branch coverage enabled
- Comprehensive omit patterns for test files and dependencies
- Multiple report formats (terminal, HTML, XML)
### Directory Structure
```
tests/
├── __init__.py # Package initialization
├── conftest.py # Shared fixtures and pytest configuration
├── README.md # Comprehensive testing documentation
├── unit/ # Unit tests
│ ├── __init__.py
│ └── test_infrastructure.py # Validation tests
└── integration/ # Integration tests
├── __init__.py
└── test_example.py # Example integration tests
```
### Shared Test Fixtures
Created comprehensive `conftest.py` with fixtures:
- `temp_dir` - Temporary directory with auto-cleanup
- `temp_file` - Temporary file with auto-cleanup
- `mock_env_vars` - Mock environment variables
- `mock_config` - Mock configuration dictionary
- `sample_data` - Sample test data structure
- `project_root` - Project root directory path
- `change_test_dir` - Change to test directory context
### Validation Tests
- ✅ 19 validation tests created to verify infrastructure
- ✅ Tests verify fixtures, markers, project structure, and pytest-mock integration
- ✅ All tests passing
### Additional Files
- ✅ Created `tests/README.md` with comprehensive documentation covering:
- How to run tests (with various options)
- Available markers and fixtures
- Writing tests (with examples)
- Coverage configuration
- CI/CD integration examples
- Troubleshooting guide
- ✅ Updated `.gitignore` to include `.claude/*` directory
## Running Tests
### Install Dependencies
```bash
poetry install
```
### Run All Tests
```bash
poetry run pytest
```
### Run with Coverage
```bash
poetry run pytest --cov=libs --cov-report=term-missing --cov-report=html
```
### Run Only Unit Tests
```bash
poetry run pytest -m unit
```
### Run Only Integration Tests
```bash
poetry run pytest -m integration
```
### Exclude Slow Tests
```bash
poetry run pytest -m "not slow"
```
### Run Specific Test Directory
```bash
# Root-level tests
poetry run pytest tests/
# Package-level tests
poetry run pytest libs/infinity_emb/tests/
```
## Coverage Reporting
The infrastructure is configured to generate multiple coverage report formats:
1. **Terminal Report**: Shows coverage summary with missing lines
2. **HTML Report**: Generated in `htmlcov/` - open `htmlcov/index.html` in browser
3. **XML Report**: Generated as `coverage.xml` for CI/CD integration
Coverage threshold is set to 80% by default, configurable in `pyproject.toml`.
## Configuration Choices
### Poetry Over UV
- Poetry was chosen because it's already used in the `libs/infinity_emb` package
- Provides mature dependency management and lock file support
- Wide ecosystem support and CI/CD integration
### Package Mode: False
- Root-level `pyproject.toml` uses `package-mode = false` since this is a monorepo
- Individual packages in `libs/` maintain their own packaging configuration
- This allows for centralized test orchestration without packaging the root
### Comprehensive Markers
Four test markers are configured:
- `unit` - Fast, isolated component tests
- `integration` - Multi-component integration tests
- `slow` - Long-running tests (can be excluded with `-m "not slow"`)
- `performance` - Benchmark and performance tests
### Coverage Configuration
- Covers code in `libs/` directory (where actual packages live)
- Excludes test files, conftest, __init__, and common patterns
- Branch coverage enabled for better test quality
- 80% threshold ensures good test coverage without being overly restrictive
## Next Steps
With this infrastructure in place, developers can:
1. ✅ Write tests in the root `tests/` directory for cross-package functionality
2. ✅ Use shared fixtures from `conftest.py` in all tests
3. ✅ Run tests consistently across the entire monorepo
4. ✅ Generate coverage reports to identify untested code
5. ✅ Integrate with CI/CD pipelines using `coverage.xml`
## Testing the Infrastructure
This PR includes 19 validation tests that verify the infrastructure itself:
```bash
poetry run pytest tests/ -v
```
Expected output:
```
============================== test session starts ==============================
...
tests/unit/test_infrastructure.py::TestInfrastructureSetup ... PASSED
tests/unit/test_infrastructure.py::TestCoverageIntegration ... PASSED
tests/unit/test_infrastructure.py::TestProjectStructure ... PASSED
...
============================== 19 passed in 0.02s ==============================
```
## Verification Checklist
- ✅ Poetry dependencies install successfully
- ✅ All validation tests pass
- ✅ Pytest markers work correctly
- ✅ Shared fixtures are accessible in tests
- ✅ Coverage reporting generates correctly
- ✅ `poetry.lock` is tracked in git (not in `.gitignore`)
- ✅ Documentation is comprehensive and clear
## Questions or Feedback?
Please let me know if you'd like any adjustments to:
- Coverage thresholds
- Test markers or organization
- Fixture implementations
- Documentation
- Any other aspect of the testing infrastructure
I'm happy to make modifications to better fit your workflow and preferences!
合并状态:未合并 关闭于 2025-11-03 4 条评论