Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit coverage context in subprocesses #443

Merged
merged 1 commit into from Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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