Skip to content

Commit dd644ab

Browse files
committed
This is the correct fix for #224. Data gets collected, and doesn't incur crazy harvesting during reporting.
1 parent 62489d0 commit dd644ab

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

coverage/control.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,12 @@ def __init__(self, data_file=None, data_suffix=None, cover_pylib=None,
179179
# Is it ok for no data to be collected?
180180
self._warn_no_data = True
181181
self._warn_unimported_source = True
182+
183+
# State machine variables:
184+
# Have we started collecting and not stopped it?
182185
self._started = False
186+
# Have we measured some data and not harvested it?
187+
self._measured = False
183188

184189
atexit.register(self._atexit)
185190

@@ -361,6 +366,7 @@ def start(self):
361366

362367
self.collector.start()
363368
self._started = True
369+
self._measured = True
364370

365371
def stop(self):
366372
"""Stop measuring code coverage."""
@@ -473,26 +479,29 @@ def _harvest_data(self):
473479
Also warn about various problems collecting data.
474480
475481
"""
476-
self.data.add_line_data(self.collector.get_line_data())
477-
self.data.add_arc_data(self.collector.get_arc_data())
478-
self.collector.reset()
479-
480-
# If there are still entries in the source_pkgs list, then we never
481-
# encountered those packages.
482-
if self._warn_unimported_source:
483-
for pkg in self.source_pkgs:
484-
self._warn("Module %s was never imported." % pkg)
485-
486-
# Find out if we got any data.
487-
summary = self.data.summary()
488-
if not summary and self._warn_no_data:
489-
self._warn("No data was collected.")
490-
491-
# Find files that were never executed at all.
492-
for src in self.source:
493-
for py_file in find_python_files(src):
494-
py_file = self.file_locator.canonical_filename(py_file)
495-
self.data.touch_file(py_file)
482+
if self._measured:
483+
self.data.add_line_data(self.collector.get_line_data())
484+
self.data.add_arc_data(self.collector.get_arc_data())
485+
self.collector.reset()
486+
487+
# If there are still entries in the source_pkgs list, then we never
488+
# encountered those packages.
489+
if self._warn_unimported_source:
490+
for pkg in self.source_pkgs:
491+
self._warn("Module %s was never imported." % pkg)
492+
493+
# Find out if we got any data.
494+
summary = self.data.summary()
495+
if not summary and self._warn_no_data:
496+
self._warn("No data was collected.")
497+
498+
# Find files that were never executed at all.
499+
for src in self.source:
500+
for py_file in find_python_files(src):
501+
py_file = self.file_locator.canonical_filename(py_file)
502+
self.data.touch_file(py_file)
503+
504+
self._measured = False
496505

497506
# Backward compatibility with version 1.
498507
def analysis(self, morf):

test/test_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def test_warnings_during_reporting(self):
408408
""")
409409
self.make_file(".coveragerc", """\
410410
[run]
411-
source =
411+
source =
412412
.
413413
xyzzy
414414
""")

0 commit comments

Comments
 (0)