Skip to content

Commit 8a7766a

Browse files
authored
Merge pull request #511 from pytest-dev/no-fail-collectonly
`--cov-fail-under` should not cause `pytest --collect-only` to fail
2 parents 5182e59 + 6925fcf commit 8a7766a

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ Authors
5050
* Brian Rutledge - https://github.com/bhrutledge
5151
* Danilo Šegan - https://github.com/dsegan
5252
* Michał Bielawski - https://github.com/D3X
53+
* Zac Hatfield-Dodds - https://github.com/Zac-HD

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ Changelog
22
=========
33

44

5+
3.1.0 (future)
6+
-------------------
7+
8+
* `--cov-fail-under` no longer causes `pytest --collect-only` to fail
9+
Contributed by Zac Hatfield-Dodds in
10+
`#511 <https://github.com/pytest-dev/pytest-cov/pull/511>`_.
11+
12+
513
3.0.0 (2021-10-04)
614
-------------------
715

src/pytest_cov/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def pytest_runtestloop(self, session):
308308
warnings.warn(CovReportWarning(message))
309309
self.cov_total = 0
310310
assert self.cov_total is not None, 'Test coverage should never be `None`'
311-
if self._failed_cov_total():
311+
if self._failed_cov_total() and not self.options.collectonly:
312312
# make sure we get the EXIT_TESTSFAILED exit code
313313
compat_session.testsfailed += 1
314314

tests/test_pytest_cov.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,19 @@ def test_cov_min_100(testdir):
389389
])
390390

391391

392+
def test_cov_min_100_passes_if_collectonly(testdir):
393+
script = testdir.makepyfile(SCRIPT)
394+
395+
result = testdir.runpytest('-v',
396+
'--cov=%s' % script.dirpath(),
397+
'--cov-report=term-missing',
398+
'--cov-fail-under=100',
399+
'--collect-only',
400+
script)
401+
402+
assert result.ret == 0
403+
404+
392405
def test_cov_min_50(testdir):
393406
script = testdir.makepyfile(SCRIPT)
394407

0 commit comments

Comments
 (0)