diff --git a/.gitignore b/.gitignore index aa232b9..56a27d0 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,8 @@ wandb/ # lock files requirements-dev.lock + +# coverage.py +htmlcov/ +.coverage +.coverage.* diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5af2b4b..4caf9e2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,3 +68,15 @@ You can enforce running tests on CPU. Tests that require a GPU will be skipped. ```bash REFINERS_TEST_DEVICE=cpu rye run pytest ``` + +You can collect [code coverage](https://github.com/nedbat/coveragepy) data while running tests with, e.g.: + +```bash +rye run test-cov +``` + +Then, browse the corresponding HTML report with: + +```bash +rye run serve-cov-report +``` diff --git a/pyproject.toml b/pyproject.toml index cd27822..124e69d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -69,6 +69,11 @@ allow-direct-references = true [tool.rye.scripts] lint = { chain = ["ruff format .", "ruff --fix ."] } serve-docs = "mkdocs serve" +test-cov = "coverage run -m pytest" +# Work around for "Couldn't parse" errors due to e.g. opencv-python: +# https://github.com/nedbat/coveragepy/issues/1653 +build-html-cov = { cmd = "coverage html", env = { PYTHONWARNINGS = "ignore:Couldn't parse::coverage.report_core" } } +serve-cov-report = { chain = ["build-html-cov", "python -m http.server 8080 -b 127.0.0.1 -d htmlcov"]} [tool.black] line-length = 120 @@ -99,3 +104,10 @@ include = ["src/refiners", "tests", "scripts"] strict = ["*"] exclude = ["**/__pycache__", "tests/weights"] reportMissingTypeStubs = "warning" + +[tool.coverage.run] +branch = true + +# Also apply to HTML output, where appropriate +[tool.coverage.report] +ignore_errors = true # see `build-html-cov` for details