From 6925fcfbb2c96e01124840c46ebbda6719fbbbcd Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sun, 12 Dec 2021 00:59:38 +1100 Subject: [PATCH] --co disables --cov-fail-under --- AUTHORS.rst | 1 + CHANGELOG.rst | 8 ++++++++ src/pytest_cov/plugin.py | 2 +- tests/test_pytest_cov.py | 13 +++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 6aa916a1..489903c2 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -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 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e6e47d95..684720ff 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 `_. + + 3.0.0 (2021-10-04) ------------------- diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 94a1e494..e915246d 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -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 diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index e7f90668..f93d352f 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -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)