Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--cov-fail-under should not cause pytest --collect-only to fail #511

Merged
merged 1 commit into from
Dec 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ Authors
* Brian Rutledge - https://github.com/bhrutledge
* Danilo Šegan - https://github.com/dsegan
* Michał Bielawski - https://github.com/D3X
* Zac Hatfield-Dodds - https://github.com/Zac-HD
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ Changelog
=========


3.1.0 (future)
-------------------

* `--cov-fail-under` no longer causes `pytest --collect-only` to fail
Contributed by Zac Hatfield-Dodds in
`#511 <https://github.com/pytest-dev/pytest-cov/pull/511>`_.


3.0.0 (2021-10-04)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def pytest_runtestloop(self, session):
warnings.warn(CovReportWarning(message))
self.cov_total = 0
assert self.cov_total is not None, 'Test coverage should never be `None`'
if self._failed_cov_total():
if self._failed_cov_total() and not self.options.collectonly:
# make sure we get the EXIT_TESTSFAILED exit code
compat_session.testsfailed += 1

Expand Down
13 changes: 13 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,19 @@ def test_cov_min_100(testdir):
])


def test_cov_min_100_passes_if_collectonly(testdir):
script = testdir.makepyfile(SCRIPT)

result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
'--cov-report=term-missing',
'--cov-fail-under=100',
'--collect-only',
script)

assert result.ret == 0


def test_cov_min_50(testdir):
script = testdir.makepyfile(SCRIPT)

Expand Down