Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pytest-dev/pytest-cov
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.1.0
Choose a base ref
...
head repository: pytest-dev/pytest-cov
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.1.1
Choose a head ref
  • 3 commits
  • 10 files changed
  • 1 contributor

Commits on Apr 5, 2025

  1. Copy the full SHA
    a59548f View commit details
  2. Update changelog.

    ionelmc committed Apr 5, 2025
    Copy the full SHA
    7f2781b View commit details
  3. Bump version: 6.1.0 → 6.1.1

    ionelmc committed Apr 5, 2025
    3
    Copy the full SHA
    9463242 View commit details
Showing with 66 additions and 13 deletions.
  1. +1 −1 .bumpversion.cfg
  2. +1 −1 .cookiecutterrc
  3. +5 −0 CHANGELOG.rst
  4. +2 −2 README.rst
  5. +1 −1 docs/conf.py
  6. +1 −1 setup.py
  7. +1 −1 src/pytest_cov/__init__.py
  8. +15 −0 src/pytest_cov/engine.py
  9. +9 −6 src/pytest_cov/plugin.py
  10. +30 −0 tests/test_pytest_cov.py
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 6.1.0
current_version = 6.1.1
commit = True
tag = True

2 changes: 1 addition & 1 deletion .cookiecutterrc
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ default_context:
sphinx_doctest: 'no'
sphinx_theme: sphinx-py3doc-enhanced-theme
test_matrix_separate_coverage: 'no'
version: 6.1.0
version: 6.1.1
version_manager: bump2version
website: http://blog.ionelmc.ro
year_from: '2010'
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -2,6 +2,11 @@
Changelog
=========

6.1.1 (2025-04-05)
------------------

* Fixed breakage that occurs when ``--cov-context`` and the ``no_cover`` marker are used together.

6.1.0 (2025-04-01)
------------------

4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
@@ -39,9 +39,9 @@ Overview
:alt: Supported implementations
:target: https://pypi.org/project/pytest-cov

.. |commits-since| image:: https://img.shields.io/github/commits-since/pytest-dev/pytest-cov/v6.1.0.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/pytest-dev/pytest-cov/v6.1.1.svg
:alt: Commits since latest release
:target: https://github.com/pytest-dev/pytest-cov/compare/v6.1.0...master
:target: https://github.com/pytest-dev/pytest-cov/compare/v6.1.1...master

.. end-badges
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
year = '2010-2024'
author = 'pytest-cov contributors'
copyright = f'{year}, {author}'
version = release = '6.1.0'
version = release = '6.1.1'

pygments_style = 'trac'
templates_path = ['.']
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ def run(self):

setup(
name='pytest-cov',
version='6.1.0',
version='6.1.1',
license='MIT',
description='Pytest plugin for measuring coverage.',
long_description='{}\n{}'.format(read('README.rst'), re.sub(':[a-z]+:`~?(.*?)`', r'``\1``', read('CHANGELOG.rst'))),
2 changes: 1 addition & 1 deletion src/pytest_cov/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""pytest-cov: avoid already-imported warning: PYTEST_DONT_REWRITE."""

__version__ = '6.1.0'
__version__ = '6.1.1'

import pytest

15 changes: 15 additions & 0 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
@@ -87,6 +87,7 @@ def __init__(self, options: argparse.Namespace, config: Union[None, object], nod
self.failed_workers = []
self.topdir = os.fspath(Path.cwd())
self.is_collocated = None
self.started = False

@contextlib.contextmanager
def ensure_topdir(self):
@@ -97,13 +98,21 @@ def ensure_topdir(self):

@_ensure_topdir
def pause(self):
self.started = False
self.cov.stop()
self.unset_env()

@_ensure_topdir
def resume(self):
self.cov.start()
self.set_env()
self.started = True

def start(self):
self.started = True

def finish(self):
self.started = False

@_ensure_topdir
def set_env(self):
@@ -295,9 +304,12 @@ def start(self):
self.cov.start()
self.set_env()

super().start()

@_ensure_topdir
def finish(self):
"""Stop coverage, save data to file and set the list of coverage objects to report on."""
super().finish()

self.unset_env()
self.cov.stop()
@@ -440,10 +452,13 @@ def start(self):
)
self.cov.start()
self.set_env()
super().start()

@_ensure_topdir
def finish(self):
"""Stop coverage and send relevant info back to the master."""
super().finish()

self.unset_env()
self.cov.stop()

15 changes: 9 additions & 6 deletions src/pytest_cov/plugin.py
Original file line number Diff line number Diff line change
@@ -284,7 +284,7 @@ def pytest_sessionstart(self, session):
self.start(engine.Central)

if self.options.cov_context == 'test':
session.config.pluginmanager.register(TestContextPlugin(self.cov_controller.cov), '_cov_contexts')
session.config.pluginmanager.register(TestContextPlugin(self.cov_controller), '_cov_contexts')

@pytest.hookimpl(optionalhook=True)
def pytest_configure_node(self, node):
@@ -408,8 +408,10 @@ def pytest_runtest_call(self, item):


class TestContextPlugin:
def __init__(self, cov):
self.cov = cov
cov_controller: 'CovController'

def __init__(self, cov_controller):
self.cov_controller = cov_controller

def pytest_runtest_setup(self, item):
self.switch_context(item, 'setup')
@@ -421,9 +423,10 @@ def pytest_runtest_call(self, item):
self.switch_context(item, 'run')

def switch_context(self, item, when):
context = f'{item.nodeid}|{when}'
self.cov.switch_context(context)
os.environ['COV_CORE_CONTEXT'] = context
if self.cov_controller.started:
context = f'{item.nodeid}|{when}'
self.cov_controller.cov.switch_context(context)
os.environ['COV_CORE_CONTEXT'] = context


@pytest.fixture
30 changes: 30 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
@@ -1942,6 +1942,36 @@ def test_contexts_not_supported(testdir):
assert result.ret != 0


def test_contexts_no_cover(testdir):
script = testdir.makepyfile("""
import pytest
def foobar():
return 1
def test_with_coverage():
foobar()
@pytest.mark.no_cover()
def test_without_coverage():
foobar()
""")
result = testdir.runpytest(
'-v',
'--cov-context=test',
'--cov=test_contexts_no_cover',
script,
)
result.stdout.fnmatch_lines(
[
'test_contexts_no_cover.py 8 1 88%',
'TOTAL 8 1 88%',
]
)
assert result.stderr.lines == []
assert result.ret == 0


def test_issue_417(testdir):
# https://github.com/pytest-dev/pytest-cov/issues/417
whatever = testdir.maketxtfile(whatever='')