Skip to content

Commit d58a8e3

Browse files
authored
Merge pull request #1807 from blueyed/improve-multiline-error-format
Improve display of continuation lines with multiline errors
2 parents 34925a3 + c163cc7 commit d58a8e3

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
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: 10 additions & 8 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:
@@ -1836,6 +1836,7 @@ def formatrepr(self):
18361836

18371837
return FixtureLookupErrorRepr(fspath, lineno, tblines, msg, self.argname)
18381838

1839+
18391840
class FixtureLookupErrorRepr(TerminalRepr):
18401841
def __init__(self, filename, firstlineno, tblines, errorstring, argname):
18411842
self.tblines = tblines
@@ -1845,19 +1846,20 @@ def __init__(self, filename, firstlineno, tblines, errorstring, argname):
18451846
self.argname = argname
18461847

18471848
def toterminal(self, tw):
1848-
#tw.line("FixtureLookupError: %s" %(self.argname), red=True)
1849+
# tw.line("FixtureLookupError: %s" %(self.argname), red=True)
18491850
for tbline in self.tblines:
18501851
tw.line(tbline.rstrip())
18511852
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)
1853+
if lines:
1854+
tw.line('{0} {1}'.format(FormattedExcinfo.fail_marker,
1855+
lines[0].strip()), red=True)
1856+
for line in lines[1:]:
1857+
tw.line('{0} {1}'.format(FormattedExcinfo.flow_marker,
1858+
line.strip()), red=True)
18581859
tw.line()
18591860
tw.line("%s:%d" % (self.filename, self.firstlineno+1))
18601861

1862+
18611863
class FixtureManager:
18621864
"""
18631865
pytest fixtures definitions and information is stored and managed

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)