From 5884bdbea49e5e71e2cd06ecfa484bb635063735 Mon Sep 17 00:00:00 2001 From: Benjamin Bossan Date: Fri, 30 Jun 2023 14:01:02 +0200 Subject: [PATCH] Add pytest-cov for reporting test coverage (#641) As discussed, this adds line coverage to the tests. This will allow us to identify parts of the code that are missing coverage and make it easier to ensure newly added code is well covered. At the moment, CI is not set up to report if new, uncovered code is being added. We could add codecov to the CI to get this functionality, but having 100% coverage for new code is not always desired, so it's debatable if it is needed. Right now, there are multiple test commands (normal, single, multi GPU). For each individual command, the coverage report would only include the lines covered by that command, so the total coverage would be underreported. It is possible to combine multiple coverage reports into a single report: https://coverage.readthedocs.io/en/stable/cmd.html#cmd-combine Combining the reports will be added in a future PR. --- .github/workflows/tests.yml | 2 +- pyproject.toml | 5 ++++- setup.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1975102cd3..33c89bee09 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,7 +43,7 @@ jobs: run: | python -m pip install --upgrade pip # cpu version of pytorch - pip install .[test] + pip install -e .[test] - name: Test with pytest run: | make test diff --git a/pyproject.toml b/pyproject.toml index a72149d682..ae9d4507a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,4 +33,7 @@ doctest_optionflags = [ "NORMALIZE_WHITESPACE", "ELLIPSIS", "NUMBER", -] \ No newline at end of file +] + +[tool.pytest.ini_options] +addopts = "--cov=src/peft --cov-report=term-missing" diff --git a/setup.py b/setup.py index 8b4978bde2..585f67a782 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ extras["quality"] = ["black ~= 22.0", "ruff>=0.0.241", "urllib3<=2.0.0"] extras["docs_specific"] = ["hf-doc-builder"] extras["dev"] = extras["quality"] + extras["docs_specific"] -extras["test"] = extras["dev"] + ["pytest", "pytest-xdist", "parameterized", "datasets", "diffusers"] +extras["test"] = extras["dev"] + ["pytest", "pytest-cov", "pytest-xdist", "parameterized", "datasets", "diffusers"] setup( name="peft",