Skip to content

Improve display of continuation lines with multiline errors #1807

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
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
7 changes: 4 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

**Bug Fixes**

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

* Text documents without any doctests no longer appear as "skipped".
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).
Expand Down
18 changes: 10 additions & 8 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import py
import pytest
from _pytest._code.code import TerminalRepr
from _pytest._code.code import FormattedExcinfo, TerminalRepr
from _pytest.mark import MarkDecorator, MarkerError

try:
Expand Down Expand Up @@ -1836,6 +1836,7 @@ def formatrepr(self):

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


class FixtureLookupErrorRepr(TerminalRepr):
def __init__(self, filename, firstlineno, tblines, errorstring, argname):
self.tblines = tblines
Expand All @@ -1845,19 +1846,20 @@ def __init__(self, filename, firstlineno, tblines, errorstring, argname):
self.argname = argname

def toterminal(self, tw):
#tw.line("FixtureLookupError: %s" %(self.argname), red=True)
# tw.line("FixtureLookupError: %s" %(self.argname), red=True)
for tbline in self.tblines:
tw.line(tbline.rstrip())
lines = self.errorstring.split("\n")
for line in lines:
if line == lines[0]:
prefix = 'E '
else:
prefix = ' '
tw.line(prefix + line.strip(), red=True)
if lines:
tw.line('{0} {1}'.format(FormattedExcinfo.fail_marker,
lines[0].strip()), red=True)
for line in lines[1:]:
tw.line('{0} {1}'.format(FormattedExcinfo.flow_marker,
line.strip()), red=True)
tw.line()
tw.line("%s:%d" % (self.filename, self.firstlineno+1))


class FixtureManager:
"""
pytest fixtures definitions and information is stored and managed
Expand Down
9 changes: 5 additions & 4 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,11 @@ def test_lookup_error(unknown):
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines([
"*ERROR*test_lookup_error*",
"*def test_lookup_error(unknown):*",
"*fixture*unknown*not found*",
"*available fixtures*",
"*ERROR at setup of test_lookup_error*",
" def test_lookup_error(unknown):*",
"E fixture 'unknown' not found",
"> available fixtures:*",
"> use 'py*test --fixtures *' for help on them.",
"*1 error*",
])
assert "INTERNAL" not in result.stdout.str()
Expand Down