Update test skills and guide (#22189)

This commit is contained in:
Ke Bao
2026-04-06 20:30:25 +08:00
committed by GitHub
parent 3178f3959f
commit 9ca2ae1c6c
2 changed files with 6 additions and 2 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ if __name__ == "__main__":
unittest.main()
```
Use `unittest.mock.patch` / `MagicMock` to mock dependencies and isolate the logic under test. If the module transitively imports GPU-only packages (e.g. `sgl_kernel`), they can be stubbed so the test runs on CPU CI. See `test/registered/unit/README.md` for details and examples.
Use `unittest.mock.patch` / `MagicMock` to mock dependencies and isolate the logic under test. If the module transitively imports GPU-only packages (e.g. `sgl_kernel`), they can be stubbed so the test runs on CPU CI. Do not modify `sys.modules` at module level — use `patch.dict` (as a class decorator or with `start`/`stop`) to ensure cleanup and avoid cross-test pollution. See `test/registered/unit/README.md` for details and examples.
**Quality bar** — test real logic (validation boundaries, state transitions, error paths, branching, etc.). Skip tests that just verify Python itself works (e.g., "does calling an abstract method raise `NotImplementedError`?", "does a dataclass store the field I assigned?"). Consolidate repetitive patterns into parameterized tests. No production code changes in test PRs.
+5 -1
View File
@@ -81,7 +81,11 @@ from sglang.srt.managers.scheduler import Scheduler
register_cpu_ci(est_time=2, suite="stage-a-test-cpu")
```
The same pattern can be applied to other GPU-only packages: try importing the real package, and if it fails, register a `sys.meta_path` finder that stubs it. See `maybe_stub_sgl_kernel()` in `python/sglang/test/test_utils.py` for the implementation.
The same pattern (`sys.meta_path` finder) can be applied to other GPU-only packages.
See `maybe_stub_sgl_kernel()` in `python/sglang/test/test_utils.py` for the
implementation. Do not directly mutate `sys.modules` at module level — pytest
imports all test files before running any, so such mutations pollute the entire
process. If you must stub, use `patch.dict("sys.modules", ...)` with proper cleanup.
## Rules