Skip to content

Assorted improvements following up #6658 #6782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2020
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
21 changes: 14 additions & 7 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,28 +1048,35 @@ def _write_entry_lines(self, tw: TerminalWriter) -> None:
character, as doing so might break line continuations.
"""

indent_size = 4
Copy link
Member

Choose a reason for hiding this comment

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

that diff was fun, without expanding it looks ike a api change


def is_fail(line):
return line.startswith("{} ".format(FormattedExcinfo.fail_marker))

if not self.lines:
return

# separate indents and source lines that are not failures: we want to
# highlight the code but not the indentation, which may contain markers
# such as "> assert 0"
fail_marker = "{} ".format(FormattedExcinfo.fail_marker)
indent_size = len(fail_marker)
indents = []
source_lines = []
failure_lines = []
seeing_failures = False
for line in self.lines:
if not is_fail(line):
is_source_line = not line.startswith(fail_marker)
if is_source_line:
assert not seeing_failures, (
"Unexpected failure lines between source lines:\n"
+ "\n".join(self.lines)
)
indents.append(line[:indent_size])
source_lines.append(line[indent_size:])
else:
seeing_failures = True
failure_lines.append(line)

tw._write_source(source_lines, indents)

# failure lines are always completely red and bold
for line in (x for x in self.lines if is_fail(x)):
for line in failure_lines:
tw.line(line, bold=True, red=True)

def toterminal(self, tw: TerminalWriter) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/_io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _write_source(self, lines: List[str], indents: Sequence[str] = ()) -> None:
self.line(indent + new_line)

def _highlight(self, source):
"""Highlight the given source code according to the "code_highlight" option"""
"""Highlight the given source code if we have markup support"""
if not self.hasmarkup:
return source
try:
Expand Down
4 changes: 3 additions & 1 deletion testing/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def requires_ordered_markup(cls, result: RunResult):
output = result.stdout.str()
assert "test session starts" in output
assert "\x1b[1m" in output
pytest.skip("doing limited testing because lacking ordered markup")
pytest.skip(
"doing limited testing because lacking ordered markup on py35"
)

return ColorMapping