Skip to content

Commit d0db73f

Browse files
authored
FIX: update code coverage configuration for installed package (#3033)
* Add coverage paths configuration * Fixup, add test * Fixup, remove cov config * Tidy comments and names
1 parent 507d262 commit d0db73f

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.github/workflows/run_tests.yml

+7-6
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,20 @@ jobs:
4444
- os: windows-latest
4545
python-version: "3.11"
4646
extras: "test"
47-
name: windows-3.11
47+
name: 3.11-windows
4848
- os: macos-latest
4949
python-version: "3.11"
5050
extras: "test"
51-
name: macos-3.11
51+
name: 3.11-macos
5252
# Also run tests with only the core dependencies, to ensure we
5353
# cover the latest version of numpy/pandas. See dsgibbons#46
5454
- os: ubuntu-latest
5555
python-version: "3.11"
5656
extras: "test-core"
57-
name: core-3.11
57+
name: 3.11-core
5858
fail-fast: false
59-
# Workaround to ensure job name stays the same, so "Required Checks" still present
59+
# Workaround to ensure previous job names stay the same
60+
# "Required Checks" enfore that a check called "run_tests (3.8)" is present
6061
name: run_tests (${{ matrix.name && matrix.name || matrix.python-version }})
6162
runs-on: ${{ matrix.os }}
6263
steps:
@@ -88,14 +89,14 @@ jobs:
8889
# - Use "append" import mode rather than default "prepend"
8990
run: >
9091
pytest --durations=20
91-
--cov=shap --cov-report=xml --cov-report=term-missing
92+
--cov --cov-report=xml
9293
--mpl-generate-summary=html --mpl-results-path=./mpl-results
9394
--import-mode=append
9495
- name: Upload mpl test report
9596
if: failure()
9697
uses: actions/upload-artifact@v3
9798
with:
98-
name: mpl-results-${{ matrix.python-version }}
99+
name: mpl-results-${{ matrix.python-version }}-${{ runner.os }}-${{ matrix.extras }}
99100
path: mpl-results/
100101
if-no-files-found: ignore
101102
- name: Upload coverage to Codecov

pyproject.toml

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ target-version = "py37"
105105
"shap/explainers/other/_maple.py" = ["ALL"]
106106
"shap/plots/colors/_colorconv.py" = ["ALL"]
107107

108+
[tool.coverage.run]
109+
source_pkgs = ["shap"]
110+
111+
[tool.coverage.paths]
112+
combine = ["shap", "*/site-packages/shap"]
113+
108114
[tool.cibuildwheel]
109115
# Restrict the set of builds to mirror the wheels available in scikit-learn. See #3028
110116
skip = ["cp36-*", "pp*", "*-musllinux_*"]

tests/test_install.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
3+
import pytest
4+
5+
6+
@pytest.mark.skipif(
7+
os.getenv("GITHUB_ACTIONS") != "true", reason="Only enforced when running on CI"
8+
)
9+
def test_importing_from_installed_package_not_local_files():
10+
11+
# If using an editable install (pip install --editable), then shap will
12+
# be imported directly from the repo. This is a common setup when developing.
13+
14+
# However when running tests on CI, we want to test against the *installed* package.
15+
# This ensures that the library is packaged correctly.
16+
17+
import shap
18+
assert "site-packages" in shap.__file__

0 commit comments

Comments
 (0)