mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
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:
@@ -10,16 +10,16 @@ Due to circular import dependencies in the pipeline module structure, the test f
|
|||||||
|
|
||||||
```
|
```
|
||||||
tests/
|
tests/
|
||||||
├── pipeline/ # Pipeline stage tests
|
├── __init__.py
|
||||||
│ ├── conftest.py # Shared fixtures and test infrastructure
|
├── unit_tests/ # Unit tests
|
||||||
│ ├── test_simple.py # Basic infrastructure tests (always pass)
|
│ ├── box/ # Box module tests
|
||||||
│ ├── test_bansess.py # BanSessionCheckStage tests
|
│ ├── config/ # Configuration tests
|
||||||
│ ├── test_ratelimit.py # RateLimit stage tests
|
│ ├── pipeline/ # Pipeline stage tests
|
||||||
│ ├── test_preproc.py # PreProcessor stage tests
|
│ │ └── conftest.py # Shared fixtures and test infrastructure
|
||||||
│ ├── test_respback.py # SendResponseBackStage tests
|
│ ├── platform/ # Platform adapter tests
|
||||||
│ ├── test_resprule.py # GroupRespondRuleCheckStage tests
|
│ ├── plugin/ # Plugin system tests
|
||||||
│ ├── test_pipelinemgr.py # PipelineManager tests
|
│ ├── provider/ # Provider tests
|
||||||
│ └── test_stages_integration.py # Integration tests
|
│ └── storage/ # Storage tests
|
||||||
└── README.md # This file
|
└── README.md # This file
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -56,29 +56,42 @@ This script automatically:
|
|||||||
|
|
||||||
### Manual test execution
|
### Manual test execution
|
||||||
|
|
||||||
#### Run all tests
|
#### Run all unit tests
|
||||||
```bash
|
```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
|
```bash
|
||||||
pytest tests/pipeline/test_simple.py -v
|
uv run pytest tests/unit_tests/pipeline/ -v
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Run specific test file
|
#### Run specific test file
|
||||||
```bash
|
```bash
|
||||||
pytest tests/pipeline/test_bansess.py -v
|
uv run pytest tests/unit_tests/pipeline/test_bansess.py -v
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Run with coverage
|
#### Run with coverage
|
||||||
```bash
|
```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
|
#### Run specific test
|
||||||
```bash
|
```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
|
### 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:
|
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
|
1. Make sure you're running from the project root directory
|
||||||
2. Ensure the virtual environment is activated
|
2. Ensure dependencies are installed: `uv sync --dev`
|
||||||
3. Try running `test_simple.py` first to verify the test infrastructure works
|
3. Try running a simple test first to verify the test infrastructure works
|
||||||
|
|
||||||
## CI/CD Integration
|
## CI/CD Integration
|
||||||
|
|
||||||
@@ -97,7 +110,7 @@ Tests are automatically run on:
|
|||||||
- Push to PR branch
|
- Push to PR branch
|
||||||
- Push to master/develop branches
|
- 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
|
## Adding New Tests
|
||||||
|
|
||||||
@@ -111,8 +124,8 @@ Create a new test file `test_<stage_name>.py`:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from pkg.pipeline.<module>.<stage> import <StageClass>
|
from langbot.pkg.pipeline.<module>.<stage> import <StageClass>
|
||||||
from pkg.pipeline import entities as pipeline_entities
|
from langbot.pkg.pipeline import entities as pipeline_entities
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@@ -128,7 +141,7 @@ async def test_stage_basic_flow(mock_app, sample_query):
|
|||||||
|
|
||||||
### 2. For additional fixtures
|
### 2. For additional fixtures
|
||||||
|
|
||||||
Add new fixtures to `conftest.py`:
|
Add new fixtures to the appropriate `conftest.py`:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
@@ -142,7 +155,7 @@ def my_custom_fixture():
|
|||||||
Use the helper functions in `conftest.py`:
|
Use the helper functions in `conftest.py`:
|
||||||
|
|
||||||
```python
|
```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 = create_stage_result(
|
||||||
result_type=pipeline_entities.ResultType.CONTINUE,
|
result_type=pipeline_entities.ResultType.CONTINUE,
|
||||||
@@ -166,7 +179,7 @@ assert_result_continue(result)
|
|||||||
### Import errors
|
### Import errors
|
||||||
Make sure you've installed the package in development mode:
|
Make sure you've installed the package in development mode:
|
||||||
```bash
|
```bash
|
||||||
uv pip install -e .
|
uv sync --dev
|
||||||
```
|
```
|
||||||
|
|
||||||
### Async test failures
|
### Async test failures
|
||||||
@@ -178,6 +191,7 @@ Check that you're mocking at the right level and using `AsyncMock` for async fun
|
|||||||
## Future Enhancements
|
## Future Enhancements
|
||||||
|
|
||||||
- [ ] Add integration tests for full pipeline execution
|
- [ ] Add integration tests for full pipeline execution
|
||||||
|
- [ ] Add E2E tests
|
||||||
- [ ] Add performance benchmarks
|
- [ ] Add performance benchmarks
|
||||||
- [ ] Add mutation testing for better coverage quality
|
- [ ] Add mutation testing for better coverage quality
|
||||||
- [ ] Add property-based testing with Hypothesis
|
- [ ] Add property-based testing with Hypothesis
|
||||||
Reference in New Issue
Block a user