File tree 4 files changed +20
-8
lines changed
4 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ Unreleased
29
29
- Fix: Complex conditionals over excluded lines could have incorrectly reported
30
30
a missing branch (`issue 1271 `_). This is now fixed.
31
31
32
+ - Fix: More exceptions are now handled when trying to parse source files for
33
+ reporting. Problems that used to terminate coverage.py can now be handled
34
+ with ``[report] ignore_errors ``. This helps with plugins failing to read
35
+ files (`django_coverage_plugin issue 78 `_).
36
+
32
37
- Fix: Removed another vestige of jQuery from the source tarball
33
38
(`issue 840 `_).
34
39
@@ -37,6 +42,7 @@ Unreleased
37
42
I'd rather not "fix" unsupported interfaces, it's actually nicer with a
38
43
default value.
39
44
45
+ .. _django_coverage_plugin issue 78 : https://github.com/nedbat/django_coverage_plugin/issues/78
40
46
.. _issue 1147 : https://github.com/nedbat/coveragepy/issues/1147
41
47
.. _issue 1271 : https://github.com/nedbat/coveragepy/issues/1271
42
48
.. _issue 1273 : https://github.com/nedbat/coveragepy/issues/1273
Original file line number Diff line number Diff line change @@ -57,9 +57,7 @@ def get_python_source(filename):
57
57
break
58
58
else :
59
59
# Couldn't find source.
60
- exc_msg = f"No source for code: '{ filename } '.\n "
61
- exc_msg += "Aborting report output, consider using -i."
62
- raise NoSource (exc_msg )
60
+ raise NoSource (f"No source for code: '{ filename } '." )
63
61
64
62
# Replace \f because of http://bugs.python.org/issue19035
65
63
source = source .replace (b'\f ' , b' ' )
Original file line number Diff line number Diff line change 5
5
6
6
import sys
7
7
8
- from coverage .exceptions import CoverageException , NoSource , NotPython
8
+ from coverage .exceptions import CoverageException , NotPython
9
9
from coverage .files import prep_patterns , FnmatchMatcher
10
10
from coverage .misc import ensure_dir_for_file , file_be_gone
11
11
@@ -70,9 +70,6 @@ def get_analysis_to_report(coverage, morfs):
70
70
for fr in sorted (file_reporters ):
71
71
try :
72
72
analysis = coverage ._analyze (fr )
73
- except NoSource :
74
- if not config .ignore_errors :
75
- raise
76
73
except NotPython :
77
74
# Only report errors for .py files, and only if we didn't
78
75
# explicitly suppress those errors.
@@ -84,5 +81,11 @@ def get_analysis_to_report(coverage, morfs):
84
81
coverage ._warn (msg , slug = "couldnt-parse" )
85
82
else :
86
83
raise
84
+ except Exception as exc :
85
+ if config .ignore_errors :
86
+ msg = f"Couldn't parse '{ fr .filename } ': { exc } " .rstrip ()
87
+ coverage ._warn (msg , slug = "couldnt-parse" )
88
+ else :
89
+ raise
87
90
else :
88
91
yield (fr , analysis )
Original file line number Diff line number Diff line change @@ -135,7 +135,12 @@ def test_no_source(self):
135
135
cov = coverage .Coverage ()
136
136
self .start_import_stop (cov , "innocuous" )
137
137
os .remove ("innocuous.py" )
138
- cov .xml_report (ignore_errors = True )
138
+ with pytest .warns (Warning ) as warns :
139
+ cov .xml_report (ignore_errors = True )
140
+ assert_coverage_warnings (
141
+ warns ,
142
+ re .compile (r"Couldn't parse '.*innocuous.py'. \(couldnt-parse\)" ),
143
+ )
139
144
self .assert_exists ("coverage.xml" )
140
145
141
146
def test_filename_format_showing_everything (self ):
You can’t perform that action at this time.
0 commit comments