From e7a7e7fb118cb3dc8a6c4898130087643305a29a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Wed, 4 Nov 2020 09:10:51 +0000 Subject: [PATCH] Inherit coverage context in subprocesses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Bernát Gábor --- src/pytest_cov/embed.py | 3 +++ src/pytest_cov/engine.py | 1 + src/pytest_cov/plugin.py | 1 + 3 files changed, 5 insertions(+) diff --git a/src/pytest_cov/embed.py b/src/pytest_cov/embed.py index 7e081fee..3adecdba 100644 --- a/src/pytest_cov/embed.py +++ b/src/pytest_cov/embed.py @@ -45,6 +45,7 @@ def init(): cov_config = os.environ.get('COV_CORE_CONFIG') cov_datafile = os.environ.get('COV_CORE_DATAFILE') cov_branch = True if os.environ.get('COV_CORE_BRANCH') == 'enabled' else None + cov_context = os.environ.get('COV_CORE_CONTEXT') if cov_datafile: if _active_cov: @@ -71,6 +72,8 @@ def init(): ) cov.load() cov.start() + if cov_context: + cov.switch_context(cov_context) cov._warn_no_data = False cov._warn_unimported_source = False return cov diff --git a/src/pytest_cov/engine.py b/src/pytest_cov/engine.py index eab06564..084e92ea 100644 --- a/src/pytest_cov/engine.py +++ b/src/pytest_cov/engine.py @@ -110,6 +110,7 @@ def unset_env(): os.environ.pop('COV_CORE_CONFIG', None) os.environ.pop('COV_CORE_DATAFILE', None) os.environ.pop('COV_CORE_BRANCH', None) + os.environ.pop('COV_CORE_CONTEXT', None) @staticmethod def get_node_desc(platform, version_info): diff --git a/src/pytest_cov/plugin.py b/src/pytest_cov/plugin.py index 2d22b309..b875f409 100644 --- a/src/pytest_cov/plugin.py +++ b/src/pytest_cov/plugin.py @@ -356,6 +356,7 @@ def pytest_runtest_call(self, item): def switch_context(self, item, when): context = "{item.nodeid}|{when}".format(item=item, when=when) self.cov.switch_context(context) + os.environ['COV_CORE_CONTEXT'] = context @pytest.fixture