Skip to content

Commit 9887c9f

Browse files
gaborbernationelmc
authored andcommitted
Inherit coverage context in subprocesses
Signed-off-by: Bernát Gábor <[email protected]>
1 parent aeefc96 commit 9887c9f

File tree

3 files changed

+5
-0
lines changed

3 files changed

+5
-0
lines changed

src/pytest_cov/embed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def init():
4545
cov_config = os.environ.get('COV_CORE_CONFIG')
4646
cov_datafile = os.environ.get('COV_CORE_DATAFILE')
4747
cov_branch = True if os.environ.get('COV_CORE_BRANCH') == 'enabled' else None
48+
cov_context = os.environ.get('COV_CORE_CONTEXT')
4849

4950
if cov_datafile:
5051
if _active_cov:
@@ -71,6 +72,8 @@ def init():
7172
)
7273
cov.load()
7374
cov.start()
75+
if cov_context:
76+
cov.switch_context(cov_context)
7477
cov._warn_no_data = False
7578
cov._warn_unimported_source = False
7679
return cov

src/pytest_cov/engine.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def unset_env():
110110
os.environ.pop('COV_CORE_CONFIG', None)
111111
os.environ.pop('COV_CORE_DATAFILE', None)
112112
os.environ.pop('COV_CORE_BRANCH', None)
113+
os.environ.pop('COV_CORE_CONTEXT', None)
113114

114115
@staticmethod
115116
def get_node_desc(platform, version_info):

src/pytest_cov/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ def pytest_runtest_call(self, item):
356356
def switch_context(self, item, when):
357357
context = "{item.nodeid}|{when}".format(item=item, when=when)
358358
self.cov.switch_context(context)
359+
os.environ['COV_CORE_CONTEXT'] = context
359360

360361

361362
@pytest.fixture

0 commit comments

Comments
 (0)