Skip to content

Commit e7a4ba4

Browse files
committed
fix: don't find HTML report as templates
1 parent 8a43a8d commit e7a4ba4

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ reading during the reporting phase, ending execution. This failure is now
138138
raised in a way that can be ignored with a .coveragerc setting of ``[report]
139139
ignore_errors=True`` (`issue 78`_).
140140

141+
When using ``source=.``, an existing coverage HTML report directory would be
142+
found and believed to be unmeasured HTML template files. This is now fixed.
143+
141144
.. _issue 78: https://github.com/nedbat/django_coverage_plugin/issues/78
142145

143146

django_coverage_plugin/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88

99

1010
def coverage_init(reg, options):
11-
reg.add_file_tracer(DjangoTemplatePlugin(options))
11+
plugin = DjangoTemplatePlugin(options)
12+
reg.add_file_tracer(plugin)
13+
reg.add_configurer(plugin)

django_coverage_plugin/plugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ def sys_info(self):
184184
)),
185185
]
186186

187+
def configure(self, config):
188+
self.html_report_dir = os.path.abspath(config.get_option("html:directory"))
189+
187190
def file_tracer(self, filename):
188191
if os.path.normcase(filename).startswith(self.django_template_dir):
189192
if not self.debug_checked:
@@ -204,6 +207,9 @@ def find_executable_files(self, src_dir):
204207
rx = r"^[^.#~!$@%^&*()+=,]+\.(" + "|".join(self.extensions) + r")$"
205208

206209
for (dirpath, dirnames, filenames) in os.walk(src_dir):
210+
if dirpath == self.html_report_dir:
211+
# Don't confuse the HTML report with HTML templates.
212+
continue
207213
for filename in filenames:
208214
if re.search(rx, filename):
209215
yield os.path.join(dirpath, filename)

tests/test_source.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,41 @@ def test_non_utf8_ignored(self):
134134
self.assert_measured_files("main.html", "static{}changelog.txt".format(os.sep))
135135
self.assert_analysis([1], name="main.html")
136136
self.cov.html_report()
137+
138+
def test_htmlcov_isnt_measured(self):
139+
# We used to find the HTML report and think it was template files.
140+
self.make_file(".coveragerc", """\
141+
[run]
142+
plugins = django_coverage_plugin
143+
source = .
144+
""")
145+
self.make_template(name="main.html", text="Hello")
146+
text = self.run_django_coverage(name="main.html")
147+
self.assertEqual(text, "Hello")
148+
149+
self.assert_measured_files("main.html")
150+
self.cov.html_report()
151+
152+
# Run coverage again with an HTML report on disk.
153+
text = self.run_django_coverage(name="main.html")
154+
self.assert_measured_files("main.html")
155+
156+
def test_custom_html_report_isnt_measured(self):
157+
# We used to find the HTML report and think it was template files.
158+
self.make_file(".coveragerc", """\
159+
[run]
160+
plugins = django_coverage_plugin
161+
source = .
162+
[html]
163+
directory = my_html_report
164+
""")
165+
self.make_template(name="main.html", text="Hello")
166+
text = self.run_django_coverage(name="main.html")
167+
self.assertEqual(text, "Hello")
168+
169+
self.assert_measured_files("main.html")
170+
self.cov.html_report()
171+
172+
# Run coverage again with an HTML report on disk.
173+
text = self.run_django_coverage(name="main.html")
174+
self.assert_measured_files("main.html")

0 commit comments

Comments
 (0)