diff --git a/AUTHORS.rst b/AUTHORS.rst index 3291067a..5230d3b5 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -2,6 +2,7 @@ Authors ======= +* GruffElixir - https://github.com/GruffElixir * Marc Schlaich - https://github.com/schlamar (\http://www.schlamar.org) * Rick van Hattem - http://wol.ph * Buck Evan - https://github.com/bukzor diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 15a028dd..7996eb26 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,9 @@ Changelog ========= +* Fixed no_cover markers and fixtures when coverage is disabled with --no-cov. + Fixes #590. + 7.1.0 (2026-03-21) ------------------ diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 9f5c3f76..c0bd9e6a 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -422,6 +422,9 @@ def pytest_terminal_summary(self, terminalreporter): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_call(self, item): + if self._disabled or self.cov_controller is None: + yield + return if item.get_closest_marker('no_cover') or 'no_cover' in getattr(item, 'fixturenames', ()): self.cov_controller.pause() yield diff --git a/tests/test_pytest_cov.py b/tests/test_pytest_cov.py index b291f432..adb83336 100644 --- a/tests/test_pytest_cov.py +++ b/tests/test_pytest_cov.py @@ -1515,6 +1515,20 @@ def test_basic(): result.stdout.fnmatch_lines(['mod* 2 * 1 * 50% * 2']) +def test_no_cover_marker_with_no_cov(testdir): + script = testdir.makepyfile( + """ +import pytest + +@pytest.mark.no_cover +def test_basic(): + pass +""" + ) + result = testdir.runpytest('-p', 'pytest_cov.plugin', '-v', '--cov=.', '--no-cov', script) + assert result.ret == 0 + + def test_no_cover_fixture(testdir): testdir.makepyfile(mod=MODULE) script = testdir.makepyfile(