From 443928f25fb8e1f3fc00d1758e4701fa631d73fc Mon Sep 17 00:00:00 2001 From: Chuck Daniels Date: Tue, 28 Jan 2025 11:53:15 -0500 Subject: [PATCH] Ignore conftest.py in code coverage (#388) * Ignore conftest.py in code coverage * Configure coverage in pyproject.toml * Do not run pytest coverage by default --- .github/codecov.yml | 4 +++- .github/workflows/main.yml | 2 +- .github/workflows/min-deps.yml | 2 +- .github/workflows/upstream.yml | 2 +- ci/environment.yml | 2 +- ci/min-deps.yml | 2 +- ci/upstream.yml | 2 +- docs/contributing.md | 24 ++++++++++++++++++++++-- pyproject.toml | 4 ++++ 9 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/codecov.yml b/.github/codecov.yml index 70390a69..5f6c394f 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -3,7 +3,8 @@ coverage: project: default: target: 75 - threshold: 0.1 + # See https://json.schemastore.org/codecov.json + threshold: "0.1%" patch: default: target: 75 @@ -14,4 +15,5 @@ comment: branches: # branch names that can post comment - "main" ignore: + - "conftest.py" - "virtualizarr/tests" # ignore folders and all its contents diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4037abea..38fb4e49 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,7 +51,7 @@ jobs: - name: Running Tests run: | - python -m pytest ./virtualizarr --run-network-tests --cov=./ --cov-report=xml --verbose + python -m pytest --run-network-tests --verbose --cov=virtualizarr --cov-report=xml - name: Upload code coverage to Codecov uses: codecov/codecov-action@v3.1.4 diff --git a/.github/workflows/min-deps.yml b/.github/workflows/min-deps.yml index 1c3a598f..c236a9ef 100644 --- a/.github/workflows/min-deps.yml +++ b/.github/workflows/min-deps.yml @@ -51,7 +51,7 @@ jobs: - name: Running Tests run: | - python -m pytest ./virtualizarr --cov=./ --cov-report=xml --verbose + python -m pytest --verbose --cov=virtualizarr --cov-report=xml - name: Upload code coverage to Codecov uses: codecov/codecov-action@v3.1.4 diff --git a/.github/workflows/upstream.yml b/.github/workflows/upstream.yml index e847cf62..74867ea5 100644 --- a/.github/workflows/upstream.yml +++ b/.github/workflows/upstream.yml @@ -51,7 +51,7 @@ jobs: - name: Running Tests run: | - python -m pytest ./virtualizarr --cov=./ --cov-report=xml --verbose + python -m pytest --verbose --cov=virtualizarr --cov-report=xml - name: Upload code coverage to Codecov uses: codecov/codecov-action@v3.1.4 diff --git a/ci/environment.yml b/ci/environment.yml index b26bb440..08dbf246 100644 --- a/ci/environment.yml +++ b/ci/environment.yml @@ -16,7 +16,7 @@ dependencies: - hdf5plugin - numcodecs # Testing - - codecov + - codecov[toml] - pre-commit - mypy - ruff diff --git a/ci/min-deps.yml b/ci/min-deps.yml index 344a4595..a0a0cf20 100644 --- a/ci/min-deps.yml +++ b/ci/min-deps.yml @@ -13,7 +13,7 @@ dependencies: - ujson - universal_pathlib # Testing - - codecov + - codecov[toml] - pre-commit - mypy - ruff diff --git a/ci/upstream.yml b/ci/upstream.yml index 1e97b165..ed9bf6fa 100644 --- a/ci/upstream.yml +++ b/ci/upstream.yml @@ -16,7 +16,7 @@ dependencies: - numcodecs - imagecodecs>=2024.6.1 # Testing - - codecov + - codecov[toml] - pre-commit - mypy - ruff diff --git a/docs/contributing.md b/docs/contributing.md index 31526971..45fc8599 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -12,10 +12,30 @@ mamba activate virtualizarr-tests pre-commit install # git checkout -b new-feature python -m pip install -e . --no-deps -python -m pytest ./virtualizarr --run-network-tests --cov=./ --cov-report=xml --verbose +python -m pytest ``` -The `--run-network-tests` argument is optional - it will run additional tests that require downloading files over the network. Skip this if you want the tests to run faster or you have no internet access. +You may also add the `--run-network-tests` option, which will run additional tests +that require downloading files over the network. Skip this if you want the tests to run +faster or you have no internet access: + +```bash +python -m pytest --run-network-tests +``` + +Further, the `pytest-cov` plugin is a test dependency, so you can generate a test +coverage report locally, if you wish (CI will automatically do so). Here are some +examples: + +```bash +python -m pytest --cov=. # Terminal (text) report (--cov=term) +python -m pytest --cov=. --cov=term-missing # Terminal report showing missing coverage +python -m pytest --cov=. --cov=html # HTML report written to htmlcov/index.html +``` + +To see all available `pytest` options added by the `pytest-cov` plugin, run +`python -m pytest -h`, or see the +[pytest-cov documentation](https://pytest-cov.readthedocs.io/en/latest/readme.html). ## Contributing documentation diff --git a/pyproject.toml b/pyproject.toml index 037c16e7..8421819e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -148,6 +148,10 @@ line-ending = "auto" [tool.ruff.lint.isort] known-first-party = ["virtualizarr"] +[tool.coverage.run] +include = ["virtualizarr/"] +omit = ["conftest.py", "virtualizarr/tests/*"] + [tool.pytest.ini_options] # See https://pytest-asyncio.readthedocs.io/en/latest/concepts.html#asyncio-event-loops # Explicitly set asyncio_default_fixture_loop_scope to eliminate the following warning: