diff options
-rw-r--r-- | CHANGES.rst | 4 | ||||
-rw-r--r-- | coverage/control.py | 10 | ||||
-rw-r--r-- | tests/test_oddball.py | 8 |
3 files changed, 20 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 349247ff..610ea4bf 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,7 +15,11 @@ Version 4.1 are seeing corrupt data files, but this lets them continue combining anyway. Prompted by `issue 418`_. +- Pyexpat C code will no longer be recorded as a source file, fixing + `issue 419`_. + .. _issue 418: https://bitbucket.org/ned/coveragepy/issues/418/json-parse-error +.. _issue 419: https://bitbucket.org/ned/coveragepy/issues/419/nosource-no-source-for-code-path-to-c Version 4.0 --- 20 September 2015 diff --git a/coverage/control.py b/coverage/control.py index 77737181..a5741a47 100644 --- a/coverage/control.py +++ b/coverage/control.py @@ -7,6 +7,7 @@ import atexit import inspect import os import platform +import re import sys import traceback @@ -289,7 +290,7 @@ class Coverage(object): # environments (virtualenv, for example), these modules may be # spread across a few locations. Look at all the candidate modules # we've imported, and take all the different ones. - for m in (atexit, inspect, os, platform, _structseq, traceback): + for m in (atexit, inspect, os, platform, re, _structseq, traceback): if m is not None and hasattr(m, "__file__"): self.pylib_dirs.add(self._canonical_dir(m)) if _structseq and not hasattr(_structseq, '__file__'): @@ -475,6 +476,11 @@ class Coverage(object): # can't do anything with the data later anyway. return nope(disp, "not a real file name") + # pyexpat does a dumb thing, calling the trace function explicitly from + # C code with a C file name. + if re.search(r"[/\\]Modules[/\\]pyexpat.c", filename): + return nope(disp, "pyexpat lies about itself") + # Jython reports the .class file to the tracer, use the source file. if filename.endswith("$py.class"): filename = filename[:-9] + ".py" @@ -805,7 +811,7 @@ class Coverage(object): """ self._init() if not self._measured: - return + return self.data self.collector.save_data(self.data) diff --git a/tests/test_oddball.py b/tests/test_oddball.py index 2ca1aa75..bca7f127 100644 --- a/tests/test_oddball.py +++ b/tests/test_oddball.py @@ -226,6 +226,14 @@ class PyexpatTest(CoverageTest): self.assertEqual(statements, [101, 102]) self.assertEqual(missing, []) + # Make sure pyexpat isn't recorded as a source file. + # https://bitbucket.org/ned/coveragepy/issues/419/nosource-no-source-for-code-path-to-c + files = cov.get_data().measured_files() + self.assertFalse( + any(f.endswith("pyexpat.c") for f in files), + "Pyexpat.c is in the measured files!: %r:" % (files,) + ) + class ExceptionTest(CoverageTest): """I suspect different versions of Python deal with exceptions differently |