Skip to content

Commit f80a6b0

Browse files
committed
Don't let parallel=True prevent reporting. Fixes #49.
1 parent d7eecfc commit f80a6b0

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ Change history for Coverage.py
55
Version 3.3.1
66
-------------
77

8+
- Using `parallel=True` in .coveragerc file prevented reporting, but now does
9+
not, fixing `issue 49`.
10+
811
- When running your code with "coverage run", if you call `sys.exit()`,
912
coverage.py will exit with that status code, fixing `issue 50`.
10-
13+
14+
.. _issue 49: http://bitbucket.org/ned/coveragepy/issue/49
1115
.. _issue 50: http://bitbucket.org/ned/coveragepy/issue/50
1216

1317

coverage/control.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ def __init__(self, data_file=None, data_suffix=None, cover_pylib=None,
105105
)
106106
else:
107107
data_suffix = None
108+
self.run_suffix = data_suffix
108109

109110
self.data = CoverageData(
110-
basename=self.config.data_file, suffix=data_suffix,
111+
basename=self.config.data_file,
111112
collector="coverage v%s" % __version__
112113
)
113114

@@ -190,6 +191,14 @@ def load(self):
190191

191192
def start(self):
192193
"""Start measuring code coverage."""
194+
if self.run_suffix:
195+
# If the .coveragerc file specifies parallel=True, then we need to
196+
# remake the data file for collection, with a suffix.
197+
from coverage import __version__
198+
self.data = CoverageData(
199+
basename=self.config.data_file, suffix=self.run_suffix,
200+
collector="coverage v%s" % __version__
201+
)
193202
if self.auto_data:
194203
self.load()
195204
# Save coverage data when Python exits.
@@ -251,14 +260,6 @@ def combine(self):
251260
current measurements.
252261
253262
"""
254-
# If the .coveragerc file specifies parallel=True, then self.data
255-
# already points to a suffixed data file. This won't be right for
256-
# combining, so make a new self.data with no suffix.
257-
from coverage import __version__
258-
self.data = CoverageData(
259-
basename=self.config.data_file,
260-
collector="coverage v%s" % __version__
261-
)
262263
self.data.combine_parallel_data()
263264

264265
def _harvest_data(self):

test/test_process.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Tests for process behavior of coverage.py."""
22

3-
import os, sys
3+
import os, sys, textwrap
44
import coverage
55

66
sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k
@@ -120,12 +120,13 @@ def test_combine_with_rc(self):
120120
data.read_file(".coverage")
121121
self.assertEqual(data.summary()['b_or_c.py'], 7)
122122

123-
# TODO
124-
## Reporting should still work even with the .rc file
125-
#out = self.run_command("coverage report")
126-
#self.assertMultiLineEqual(out, """\
127-
# hello
128-
# """)
123+
# Reporting should still work even with the .rc file
124+
out = self.run_command("coverage report")
125+
self.assertMultiLineEqual(out, textwrap.dedent("""\
126+
Name Stmts Exec Cover
127+
----------------------------
128+
b_or_c 7 7 100%
129+
"""))
129130

130131
def test_missing_source_file(self):
131132
# Check what happens if the source is missing when reporting happens.

0 commit comments

Comments
 (0)