Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Authors
=======

* anticipate218 - https://github.com/anticipate218
* GruffElixir - https://github.com/GruffElixir
* Marc Schlaich - https://github.com/schlamar (\http://www.schlamar.org)
* Rick van Hattem - http://wol.ph
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog
Unreleased
----------

* Write Markdown reports as UTF-8 so Unicode source filenames work on systems
with other default text encodings.

* Fixed no_cover markers and fixtures when coverage is disabled with --no-cov.
Fixes #590.
* Document the import-path difference between ``coverage run -m pytest`` and ``pytest --cov`` for users migrating from coverage.py.
Expand Down
4 changes: 2 additions & 2 deletions src/pytest_cov/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ def summary(self, stream):
# Produce Markdown report if wanted.
if 'markdown' in self.cov_report:
output = self.cov_report['markdown']
with Path(output).open('w') as output_file:
with Path(output).open('w', encoding='utf-8') as output_file:
self.cov.report(ignore_errors=True, file=output_file, output_format='markdown')
stream.write(f'Coverage Markdown information written to file {output}\n')

# Produce Markdown report if wanted, appending to output file
if 'markdown-append' in self.cov_report:
output = self.cov_report['markdown-append']
with Path(output).open('a') as output_file:
with Path(output).open('a', encoding='utf-8') as output_file:
self.cov.report(ignore_errors=True, file=output_file, output_format='markdown')
stream.write(f'Coverage Markdown information appended to file {output}\n')

Expand Down
36 changes: 36 additions & 0 deletions tests/test_pytest_cov.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,42 @@ def test_markdown_append_output_dir(testdir):
assert result.ret == 0


@pytest.mark.parametrize('report', ['markdown', 'markdown-append'])
def test_markdown_unicode_filenames(testdir, monkeypatch, report):
monkeypatch.setenv('PYTHONIOENCODING', 'utf-8')
script = testdir.makepyfile(test_unicode_é=SCRIPT2)
testdir.makeconftest(
"""
from pathlib import Path

original_open = Path.open

def ascii_default_open(self, mode='r', buffering=-1, encoding=None, errors=None, newline=None):
if self.name == 'coverage.md' and 'b' not in mode and encoding is None:
encoding = 'ascii'
return original_open(self, mode, buffering, encoding, errors, newline)

def pytest_configure():
Path.open = ascii_default_open

def pytest_unconfigure():
Path.open = original_open
"""
)
output = Path(str(testdir.tmpdir)) / 'coverage.md'
prefix = 'Existing report\n'
if report == 'markdown-append':
output.write_text(prefix, encoding='utf-8')

result = testdir.runpytest('-v', f'--cov={script.dirpath()}', f'--cov-report={report}:coverage.md', script)

assert result.ret == 0
content = output.read_text(encoding='utf-8')
assert r'test\_unicode\_é.py' in content
if report == 'markdown-append':
assert content.startswith(prefix)


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

Expand Down