docs(tests): update README to reflect current test layout

- Fix stale paths: tests/pipeline → tests/unit_tests/pipeline
- Update CI Python versions: 3.11, 3.12, 3.13
- Add test directory structure for box, config, platform, plugin, provider, storage
- Document pytest markers and uv commands
- Mention planned E2E tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
huanghuoguoguo
2026-05-08 13:49:23 +08:00
parent 4bb0b49907
commit 37641f05f2

View File

@@ -10,16 +10,16 @@ Due to circular import dependencies in the pipeline module structure, the test f
```
tests/
├── pipeline/ # Pipeline stage tests
│ ├── conftest.py # Shared fixtures and test infrastructure
│ ├── test_simple.py # Basic infrastructure tests (always pass)
│ ├── test_bansess.py # BanSessionCheckStage tests
│ ├── test_ratelimit.py # RateLimit stage tests
├── test_preproc.py # PreProcessor stage tests
│ ├── test_respback.py # SendResponseBackStage tests
│ ├── test_resprule.py # GroupRespondRuleCheckStage tests
│ ├── test_pipelinemgr.py # PipelineManager tests
│ └── test_stages_integration.py # Integration tests
├── __init__.py
├── unit_tests/ # Unit tests
│ ├── box/ # Box module tests
│ ├── config/ # Configuration tests
│ ├── pipeline/ # Pipeline stage tests
│ └── conftest.py # Shared fixtures and test infrastructure
│ ├── platform/ # Platform adapter tests
│ ├── plugin/ # Plugin system tests
│ ├── provider/ # Provider tests
│ └── storage/ # Storage tests
└── README.md # This file
```
@@ -56,29 +56,42 @@ This script automatically:
### Manual test execution
#### Run all tests
#### Run all unit tests
```bash
pytest tests/pipeline/
uv run pytest tests/unit_tests/ --cov=langbot --cov-report=xml --cov-report=term
```
#### Run only simple tests (no imports, always pass)
#### Run specific test module
```bash
pytest tests/pipeline/test_simple.py -v
uv run pytest tests/unit_tests/pipeline/ -v
```
#### Run specific test file
```bash
pytest tests/pipeline/test_bansess.py -v
uv run pytest tests/unit_tests/pipeline/test_bansess.py -v
```
#### Run with coverage
```bash
pytest tests/pipeline/ --cov=pkg/pipeline --cov-report=html
uv run pytest tests/unit_tests/pipeline/ --cov=langbot --cov-report=html
```
#### Run specific test
```bash
pytest tests/pipeline/test_bansess.py::test_bansess_whitelist_allow -v
uv run pytest tests/unit_tests/pipeline/test_bansess.py::test_bansess_whitelist_allow -v
```
### Using markers
```bash
# Run only unit tests
uv run pytest tests/unit_tests/ -m unit
# Run only integration tests (when available)
uv run pytest tests/ -m integration
# Skip slow tests
uv run pytest tests/unit_tests/ -m "not slow"
```
### Known Issues
@@ -86,8 +99,8 @@ pytest tests/pipeline/test_bansess.py::test_bansess_whitelist_allow -v
Some tests may encounter circular import errors. This is a known issue with the current module structure. The test infrastructure is designed to work around this using lazy imports, but if you encounter issues:
1. Make sure you're running from the project root directory
2. Ensure the virtual environment is activated
3. Try running `test_simple.py` first to verify the test infrastructure works
2. Ensure dependencies are installed: `uv sync --dev`
3. Try running a simple test first to verify the test infrastructure works
## CI/CD Integration
@@ -97,7 +110,7 @@ Tests are automatically run on:
- Push to PR branch
- Push to master/develop branches
The workflow runs tests on Python 3.10, 3.11, and 3.12 to ensure compatibility.
The workflow runs tests on Python 3.11, 3.12, and 3.13 to ensure compatibility.
## Adding New Tests
@@ -111,8 +124,8 @@ Create a new test file `test_<stage_name>.py`:
"""
import pytest
from pkg.pipeline.<module>.<stage> import <StageClass>
from pkg.pipeline import entities as pipeline_entities
from langbot.pkg.pipeline.<module>.<stage> import <StageClass>
from langbot.pkg.pipeline import entities as pipeline_entities
@pytest.mark.asyncio
@@ -128,7 +141,7 @@ async def test_stage_basic_flow(mock_app, sample_query):
### 2. For additional fixtures
Add new fixtures to `conftest.py`:
Add new fixtures to the appropriate `conftest.py`:
```python
@pytest.fixture
@@ -142,7 +155,7 @@ def my_custom_fixture():
Use the helper functions in `conftest.py`:
```python
from tests.pipeline.conftest import create_stage_result, assert_result_continue
from tests.unit_tests.pipeline.conftest import create_stage_result, assert_result_continue
result = create_stage_result(
result_type=pipeline_entities.ResultType.CONTINUE,
@@ -166,7 +179,7 @@ assert_result_continue(result)
### Import errors
Make sure you've installed the package in development mode:
```bash
uv pip install -e .
uv sync --dev
```
### Async test failures
@@ -178,6 +191,7 @@ Check that you're mocking at the right level and using `AsyncMock` for async fun
## Future Enhancements
- [ ] Add integration tests for full pipeline execution
- [ ] Add E2E tests
- [ ] Add performance benchmarks
- [ ] Add mutation testing for better coverage quality
- [ ] Add property-based testing with Hypothesis
- [ ] Add property-based testing with Hypothesis