Skip to content

Commit 960f85d

Browse files
authored
Add pytest coverage for liger-kernel (#876)
## Summary <!--- This is a required section; please describe the main purpose of this proposed code change. ---> This PR adds [pytest-cov](https://pypi.org/project/pytest-cov/) which helps measure test coverage and can help improve overall test coverage/ diagnose test which are slow or failing. Also, I've added [pytest-asyncio](https://pypi.org/project/pytest-asyncio/) which was being used in pyproject.toml, but was not added as a dev dependency. Could you please review? cc: @lancerts , @shimizust <!--- ## Details This is an optional section; is there anything specific that reviewers should be aware of? ---> ## Testing Done <!--- This is a required section; please describe how this change was tested. ---> <!-- Replace BLANK with your device type. For example, A100-80G-PCIe Complete the following tasks before sending your PR, and replace `[ ]` with `[x]` to indicate you have done them. --> - Hardware Type: <BLANK> - [ ] run `make test` to ensure correctness - [ ] run `make checkstyle` to ensure code style - [ ] run `make test-convergence` to ensure convergence
1 parent 0b34362 commit 960f85d

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ uv.lock
2323

2424
# Benchmark images
2525
benchmark/visualizations
26-
.vscode/
26+
.vscode/
27+
.coverage

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ all: checkstyle test test-convergence
55

66
# Command to run pytest for correctness tests
77
test:
8-
python -m pytest --disable-warnings test/ --ignore=test/convergence
8+
python -m pytest --disable-warnings \
9+
-n auto \
10+
--dist=load \
11+
--cov=src/liger_kernel \
12+
--cov-report=term-missing \
13+
--ignore=test/convergence \
14+
test/
15+
coverage combine
16+
coverage report -m
17+
coverage html
918

1019
# Command to run ruff for linting and formatting code
1120
checkstyle:

pyproject.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,36 @@ pythonpath = ["src", "."]
2424
asyncio_mode = "auto"
2525
log_cli = true
2626
log_cli_level = "INFO"
27+
addopts = [
28+
"-n", "auto",
29+
"--dist=load", # use "load" to distribute tests and let pytest-cov combine coverage
30+
"--cov=src/liger_kernel",
31+
"--cov-report=term-missing",
32+
"--cov-report=html",
33+
"--cov-config=pyproject.toml",
34+
"--durations=0"
35+
]
36+
python_files = "test_*.py"
37+
testpaths = ["test/"]
38+
39+
[tool.coverage.run]
40+
branch = true
41+
parallel = true
42+
source = ["src/liger_kernel"]
43+
# xdist uses subprocesses; "multiprocessing" is a safe concurrency choice
44+
concurrency = ["multiprocessing"]
45+
46+
[tool.coverage.paths]
47+
liger_kernel = [
48+
"src/liger_kernel",
49+
"*/site-packages/liger_kernel"
50+
]
51+
52+
[tool.coverage.report]
53+
omit = ["test/*"]
54+
show_missing = true
55+
skip_covered = false
56+
2757

2858
[tool.ruff]
2959
line-length = 120

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def get_optional_dependencies():
3838
"isort>=5.13.2",
3939
"pytest>=7.1.2",
4040
"pytest-xdist",
41+
"pytest-cov",
42+
"pytest-asyncio",
4143
"pytest-rerunfailures",
4244
"datasets>=2.19.2",
4345
"seaborn",

0 commit comments

Comments
 (0)