Skip to content

Commit 1de3759

Browse files
test(backport): Use coverage over pytest-cov (#2495)
* Backport parts of PR #2054
1 parent 902ffce commit 1de3759

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

.coveragerc

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ jobs:
6060
- name: List installed Python packages
6161
run: python -m pip list
6262

63-
- name: Test with pytest
63+
- name: Test with pytest and coverage
6464
run: |
65-
pytest --ignore tests/benchmarks/ --ignore tests/contrib --ignore tests/test_notebooks.py
65+
coverage run --module pytest --ignore tests/contrib --ignore tests/benchmarks --ignore tests/test_notebooks.py
6666
6767
- name: Launch a tmate session if tests fail
6868
if: failure() && github.event_name == 'workflow_dispatch'
6969
uses: mxschmitt/action-tmate@v3
7070

71+
- name: Coverage report for core project
72+
run: |
73+
coverage report
74+
coverage xml
75+
7176
# Report coverage for oldest and newest Python tested to deal with version differences
7277
- name: Report core project coverage with Codecov
7378
if: >-
@@ -82,7 +87,12 @@ jobs:
8287

8388
- name: Test Contrib module with pytest
8489
run: |
85-
pytest tests/contrib --mpl --mpl-baseline-path tests/contrib/baseline
90+
coverage run --append --module pytest tests/contrib --mpl --mpl-baseline-path tests/contrib/baseline
91+
92+
- name: Coverage report with contrib
93+
run: |
94+
coverage report
95+
coverage xml
8696
8797
- name: Report contrib coverage with Codecov
8898
if: github.event_name != 'schedule' && matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest'

pyproject.toml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,9 @@ all = ["pyhf[backends,xmlio,contrib,shellcomplete]"]
9898

9999
# Developer extras
100100
test = [
101-
"pyhf[all]",
102101
"scikit-hep-testdata>=0.4.11",
103102
"pytest>=6.0",
104-
"pytest-cov>=2.5.1",
103+
"coverage[toml]>=6.0.0",
105104
"pytest-mock",
106105
"requests-mock>=1.9.0",
107106
"pytest-benchmark[histogram]",
@@ -131,7 +130,7 @@ docs = [
131130
"ipython!=8.7.0", # c.f. https://github.com/scikit-hep/pyhf/pull/2068
132131
]
133132
develop = [
134-
"pyhf[test,docs]",
133+
"pyhf[all,test,docs]",
135134
"tbump>=6.7.0",
136135
"pre-commit",
137136
"nox",
@@ -181,14 +180,9 @@ minversion = "6.0"
181180
xfail_strict = true
182181
addopts = [
183182
"-ra",
184-
"--cov=pyhf",
185-
"--cov-branch",
186183
"--showlocals",
187184
"--strict-markers",
188185
"--strict-config",
189-
"--cov-report=term-missing",
190-
"--cov-report=xml",
191-
"--cov-report=html",
192186
"--doctest-modules",
193187
"--doctest-glob='*.rst'",
194188
]
@@ -232,7 +226,22 @@ filterwarnings = [
232226
'ignore:`np.bool8` is a deprecated alias for `np.bool_`:DeprecationWarning', # numpy via tensorflow
233227
"ignore:module 'sre_constants' is deprecated:DeprecationWarning", # tensorflow v2.12.0+ for Python 3.11+
234228
"ignore:ml_dtypes.float8_e4m3b11 is deprecated.", #FIXME: Can remove when jaxlib>=0.4.12
229+
"ignore:jsonschema.RefResolver is deprecated as of v4.18.0, in favor of the:DeprecationWarning", # Issue #2139
235230
"ignore:Skipping device Apple Paravirtual device that does not support Metal 2.0:UserWarning", # Can't fix given hardware/virtualized device
231+
'ignore:Type google._upb._message.[A-Z]+ uses PyType_Spec with a metaclass that has custom:DeprecationWarning', # protobuf via tensorflow
232+
]
233+
234+
[tool.coverage.run]
235+
source = ["pyhf"]
236+
branch = true
237+
omit = ["*/pyhf/typing.py"]
238+
239+
[tool.coverage.report]
240+
precision = 1
241+
sort = "cover"
242+
show_missing = true
243+
exclude_also = [
244+
"if TYPE_CHECKING:"
236245
]
237246

238247
[tool.mypy]

0 commit comments

Comments
 (0)