8000 Strip ANSI escape sequences when ansi2html is missing by BeyondEvil · Pull Request #315 · pytest-dev/pytest-html · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
6 changes: 6 additions & 0 deletions pytest_html/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from . import extras
from . import __version__, __pypi_url__

from _pytest.logging import _remove_ansi_escape_sequences


def pytest_addhooks(pluginmanager):
from . import hooks
Expand Down Expand Up @@ -287,9 +289,13 @@ def append_log_html(self, report, additional_html):
header, content = map(escape, section)
log.append(f" {header:-^80} ")
log.append(html.br())

if ANSI:
converter = Ansi2HTMLConverter(inline=False, escaped=False)
content = converter.convert(content, full=False)
else:
content = _remove_ansi_escape_sequences(content)

log.append(raw(content))
log.append(html.br())

Expand Down
23 changes: 23 additions & 0 deletions testing/test_pytest_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,29 @@ def test_ansi():
else:
assert content not in html

def test_ansi_escape_sequence_removed(self, testdir):
testdir.makeini(
r"""
[pytest]
log_cli = 1
log_cli_level = INFO
"""
)
testdir.makepyfile(
r"""
import logging
logging.basicConfig()
LOGGER = logging.getLogger()
def test_ansi():
LOGGER.info("ANSI removed")
"""
)
result, html = run(
testdir, "report.html", "--self-contained-html", "--color=yes"
)
assert result.ret == 0
assert not re.search(r"\[[\d;]+m", html)

@pytest.mark.parametrize("content", [("'foo'"), ("u'\u0081'")])
def test_utf8_longrepr(self, testdir, content):
testdir.makeconftest(
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ commands = pre-commit run --all-files --show-diff-on-failure
[flake8]
max-line-length = 88
exclude = .eggs,.tox
ignore = E203
# rationale here:
# https://github.com/psf/black/blob/master/docs/the_black_code_style.md#slices
extend-ignore = E203
Comment on lines +27 to +29
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @ssbarnea

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already approved but apparently I do not get enough rights for the vote to matter (is gray, not green).


[pytest]
testpaths = testing
Expand Down
0