Skip to content

Commit

Permalink
Inherit coverage context in subprocesses
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat authored and ionelmc committed Nov 4, 2020
1 parent aeefc96 commit 9887c9f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/pytest_cov/embed.py
Expand Up @@ -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:
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/pytest_cov/engine.py
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions src/pytest_cov/plugin.py
Expand Up @@ -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
Expand Down

0 comments on commit 9887c9f

Please sign in to comment.