Skip to content

Commit 29ec412

Browse files
committed
Improve display of continuation lines with multiline errors
Fixes pytest-dev#717. Follow-up to pytest-dev#1762.
1 parent 34925a3 commit 29ec412

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
**Bug Fixes**
55

6-
* Add an 'E' to the first line of error messages from FixtureLookupErrorRepr.
7-
Fixes `#717`_. Thanks `@blueyed`_ for reporting, `@eolo999`_ for the PR
8-
and `@tomviner`_ for his guidance during EuroPython2016 sprint.
6+
* Improve error message with fixture lookup errors: add an 'E' to the first
7+
line and '>' to the rest. Fixes `#717`_. Thanks `@blueyed`_ for reporting and
8+
a PR, `@eolo999`_ for the initial PR and `@tomviner`_ for his guidance during
9+
EuroPython2016 sprint.
910

1011
* Text documents without any doctests no longer appear as "skipped".
1112
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).

_pytest/python.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import py
1111
import pytest
12-
from _pytest._code.code import TerminalRepr
12+
from _pytest._code.code import FormattedExcinfo, TerminalRepr
1313
from _pytest.mark import MarkDecorator, MarkerError
1414

1515
try:
@@ -1849,12 +1849,12 @@ def toterminal(self, tw):
18491849
for tbline in self.tblines:
18501850
tw.line(tbline.rstrip())
18511851
lines = self.errorstring.split("\n")
1852-
for line in lines:
1853-
if line == lines[0]:
1854-
prefix = 'E '
1855-
else:
1856-
prefix = ' '
1857-
tw.line(prefix + line.strip(), red=True)
1852+
if lines:
1853+
tw.line('{} {}'.format(FormattedExcinfo.fail_marker,
1854+
lines[0].strip()), red=True)
1855+
for line in lines[1:]:
1856+
tw.line('{} {}'.format(FormattedExcinfo.flow_marker,
1857+
line.strip()), red=True)
18581858
tw.line()
18591859
tw.line("%s:%d" % (self.filename, self.firstlineno+1))
18601860

testing/python/fixture.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,11 @@ def test_lookup_error(unknown):
395395
""")
396396
result = testdir.runpytest()
397397
result.stdout.fnmatch_lines([
398-
"*ERROR*test_lookup_error*",
399-
"*def test_lookup_error(unknown):*",
400-
"*fixture*unknown*not found*",
401-
"*available fixtures*",
398+
"*ERROR at setup of test_lookup_error*",
399+
" def test_lookup_error(unknown):*",
400+
"E fixture 'unknown' not found",
401+
"> available fixtures:*",
402+
"> use 'py*test --fixtures *' for help on them.",
402403
"*1 error*",
403404
])
404405
assert "INTERNAL" not in result.stdout.str()

0 commit comments

Comments
 (0)