diff options
-rw-r--r-- | CHANGES.txt | 4 | ||||
-rw-r--r-- | coverage/control.py | 17 |
2 files changed, 20 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 1675e985..69f005b6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,6 +17,10 @@ Version 3.4a1 module names. If provided, coverage.py will only measure execution in those source files. +- Various warnings are printed to stderr for problems encountered during data + measurement: if a ``--source`` module has no Python source to measure, or is + never encountered at all, or if no data is collected. + - The reporting commands (report, annotate, html, and xml) now have an ``--include`` switch to restrict reporting to modules beginning with those prefixes, similar to the existing ``--omit`` switch. Thanks, Zooko. diff --git a/coverage/control.py b/coverage/control.py index a21a697a..1268b3d2 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -236,6 +236,10 @@ class coverage(object): print("should_trace: %r -> %r" % (filename, ret)) return ret + def _warn(self, msg): + """Use `msg` as a warning.""" + sys.stderr.write("Warning: " + msg + "\n") + def _abs_files(self, files): """Return a list of absolute file names for the names in `files`.""" files = files or [] @@ -260,7 +264,7 @@ class coverage(object): try: pkg_file = mod.__file__ except AttributeError: - print("WHOA! No file for module %s" % pkg) + self._warn("Module %s has no python source." % pkg) else: d, f = os.path.split(pkg_file) if f.startswith('__init__.'): @@ -318,8 +322,19 @@ class coverage(object): def stop(self): """Stop measuring code coverage.""" self.collector.stop() + + # If there are still entries in the source_pkgs list, then we never + # encountered those packages. + for pkg in self.source_pkgs: + self._warn("Source module %s was never encountered." % pkg) + self._harvest_data() + # Find out if we got any data. + summary = self.data.summary() + if not summary: + self._warn("No data was collected.") + def erase(self): """Erase previously-collected coverage data. |