Skip to content

Commit

Permalink
Fix issue found in #165 - on Windows env vars are not passed around i…
Browse files Browse the repository at this point in the history
…f they are empty for some reason.
  • Loading branch information
ionelmc committed Jul 30, 2017
1 parent de3feea commit 2abacc5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/pytest_cov/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def init():
import coverage

# Determine all source roots.
if not cov_source:
if cov_source == os.pathsep:
cov_source = None
else:
cov_source = cov_source.split(os.pathsep)
if not cov_config:
if cov_config == os.pathsep:
cov_config = True

# Activate coverage for this process.
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def __init__(self, cov_source, cov_report, cov_config, cov_append, cov_branch, c
def set_env(self):
"""Put info about coverage into the env so that subprocesses can activate coverage."""
if self.cov_source is None:
os.environ['COV_CORE_SOURCE'] = ''
os.environ['COV_CORE_SOURCE'] = os.pathsep
else:
os.environ['COV_CORE_SOURCE'] = os.pathsep.join(self.cov_source)
config_file = os.path.abspath(self.cov_config)
if os.path.exists(config_file):
os.environ['COV_CORE_CONFIG'] = config_file
else:
os.environ['COV_CORE_CONFIG'] = ''
os.environ['COV_CORE_CONFIG'] = os.pathsep
os.environ['COV_CORE_DATAFILE'] = os.path.abspath(self.cov.config.data_file)
if self.cov_branch:
os.environ['COV_CORE_BRANCH'] = 'enabled'
Expand Down
29 changes: 29 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,35 @@ def test_run_target():
assert result.ret == 0


def test_multiprocessing_subprocess_no_source(testdir):
py.test.importorskip('multiprocessing.util')

script = testdir.makepyfile('''
import multiprocessing
def target_fn():
a = True
return a
def test_run_target():
p = multiprocessing.Process(target=target_fn)
p.start()
p.join()
''')

result = testdir.runpytest('-v',
'--cov',
'--cov-report=term-missing',
script)

result.stdout.fnmatch_lines([
'*- coverage: platform *, python * -*',
'test_multiprocessing_subprocess* 8 * 100%*',
'*1 passed*'
])
assert result.ret == 0


@pytest.mark.skipif('sys.platform == "win32"',
reason="multiprocessing don't support clean process temination on Windows")
def test_multiprocessing_subprocess_with_terminate(testdir):
Expand Down

0 comments on commit 2abacc5

Please sign in to comment.