[CI] Add ut coverage tool (#20628)

This commit is contained in:
Ke Bao
2026-03-15 21:13:45 +08:00
committed by GitHub
parent 45dd06f4e0
commit e2be31824f
3 changed files with 27 additions and 0 deletions

16
.coveragerc Normal file
View File

@@ -0,0 +1,16 @@
[run]
source = python/sglang/srt
omit =
*/test/*
*/__pycache__/*
[report]
show_missing = true
exclude_lines =
pragma: no cover
if __name__ == .__main__.:
raise NotImplementedError
if TYPE_CHECKING
[html]
directory = htmlcov

View File

@@ -141,6 +141,8 @@ test = [
"parameterized",
"peft",
"pytest",
"pytest-cov",
"diff-cover",
"sentence_transformers",
"tabulate",
]

View File

@@ -22,6 +22,15 @@ Tests can use CPU or GPU — the key criterion is **no server process**.
pytest test/registered/unit/ -v # all unit tests
pytest test/registered/unit/mem_cache/ -v # one module
```
5. Run with coverage:
```bash
# summary
pytest test/registered/unit/ --cov --cov-config=.coveragerc -v
# PR incremental check (require ≥60% on changed lines)
pytest test/registered/unit/ --cov --cov-config=.coveragerc --cov-report=xml
diff-cover coverage.xml --compare-branch=origin/main --fail-under=60
```
## Example