Skip to content

Commit

Permalink
Properly deal with configurable HTML output dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Sep 10, 2019
1 parent f6ca451 commit 1729c03
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/pytest_cov/engine.py
Expand Up @@ -132,12 +132,14 @@ def summary(self, stream):
# Produce html report if wanted.
if 'html' in self.cov_report:
total = self.cov.html_report(ignore_errors=True, directory=self.cov_report['html'])
stream.write('Coverage HTML written to dir %s\n' % self.cov_report['html'])
dest_dir = self.cov_report['html'] or self.cov.config.html_dir
stream.write('Coverage HTML written to dir %s\n' % dest_dir)

# Produce xml report if wanted.
if 'xml' in self.cov_report:
total = self.cov.xml_report(ignore_errors=True, outfile=self.cov_report['xml'])
stream.write('Coverage XML written to file %s\n' % self.cov_report['xml'])
out_file = self.cov_report['xml'] or self.cov.config.xml_output
stream.write('Coverage XML written to file %s\n' % out_file)

return total

Expand Down
43 changes: 42 additions & 1 deletion tests/test_pytest_cov.py
Expand Up @@ -248,7 +248,26 @@ def test_annotate_output_dir(testdir):
assert result.ret == 0


def test_html_output_dir(testdir, prop):
def test_html(testdir):
script = testdir.makepyfile(SCRIPT)

result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
'--cov-report=html',
script)

result.stdout.fnmatch_lines([
'*- coverage: platform *, python * -*',
'Coverage HTML written to dir htmlcov',
'*10 passed*',
])
dest_dir = testdir.tmpdir.join('htmlcov')
assert dest_dir.check(dir=True)
assert dest_dir.join("index.html").check()
assert result.ret == 0


def test_html_output_dir(testdir):
script = testdir.makepyfile(SCRIPT)

result = testdir.runpytest('-v',
Expand All @@ -267,6 +286,28 @@ def test_html_output_dir(testdir, prop):
assert result.ret == 0


def test_html_configured_output_dir(testdir):
script = testdir.makepyfile(SCRIPT)
testdir.tmpdir.join('.coveragerc').write("""
[html]
directory = somewhere
""")
result = testdir.runpytest('-v',
'--cov=%s' % script.dirpath(),
'--cov-report=html',
script)

result.stdout.fnmatch_lines([
'*- coverage: platform *, python * -*',
'Coverage HTML written to dir somewhere',
'*10 passed*',
])
dest_dir = testdir.tmpdir.join('somewhere')
assert dest_dir.check(dir=True)
assert dest_dir.join("index.html").check()
assert result.ret == 0


def test_xml_output_dir(testdir):
script = testdir.makepyfile(SCRIPT)

Expand Down

0 comments on commit 1729c03

Please sign in to comment.