Improve display of continuation lines with multiline errors
Fixes https://github.com/pytest-dev/pytest/issues/717. Follow-up to https://github.com/pytest-dev/pytest/pull/1762.
This commit is contained in:
parent
34925a31a9
commit
c163cc7937
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
**Bug Fixes**
|
**Bug Fixes**
|
||||||
|
|
||||||
* Add an 'E' to the first line of error messages from FixtureLookupErrorRepr.
|
* Improve error message with fixture lookup errors: add an 'E' to the first
|
||||||
Fixes `#717`_. Thanks `@blueyed`_ for reporting, `@eolo999`_ for the PR
|
line and '>' to the rest. Fixes `#717`_. Thanks `@blueyed`_ for reporting and
|
||||||
and `@tomviner`_ for his guidance during EuroPython2016 sprint.
|
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".
|
* Text documents without any doctests no longer appear as "skipped".
|
||||||
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).
|
Thanks `@graingert`_ for reporting and providing a full PR (`#1580`_).
|
||||||
|
|
|
@ -9,7 +9,7 @@ import warnings
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest._code.code import TerminalRepr
|
from _pytest._code.code import FormattedExcinfo, TerminalRepr
|
||||||
from _pytest.mark import MarkDecorator, MarkerError
|
from _pytest.mark import MarkDecorator, MarkerError
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -1836,6 +1836,7 @@ class FixtureLookupError(LookupError):
|
||||||
|
|
||||||
return FixtureLookupErrorRepr(fspath, lineno, tblines, msg, self.argname)
|
return FixtureLookupErrorRepr(fspath, lineno, tblines, msg, self.argname)
|
||||||
|
|
||||||
|
|
||||||
class FixtureLookupErrorRepr(TerminalRepr):
|
class FixtureLookupErrorRepr(TerminalRepr):
|
||||||
def __init__(self, filename, firstlineno, tblines, errorstring, argname):
|
def __init__(self, filename, firstlineno, tblines, errorstring, argname):
|
||||||
self.tblines = tblines
|
self.tblines = tblines
|
||||||
|
@ -1845,19 +1846,20 @@ class FixtureLookupErrorRepr(TerminalRepr):
|
||||||
self.argname = argname
|
self.argname = argname
|
||||||
|
|
||||||
def toterminal(self, tw):
|
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:
|
for tbline in self.tblines:
|
||||||
tw.line(tbline.rstrip())
|
tw.line(tbline.rstrip())
|
||||||
lines = self.errorstring.split("\n")
|
lines = self.errorstring.split("\n")
|
||||||
for line in lines:
|
if lines:
|
||||||
if line == lines[0]:
|
tw.line('{0} {1}'.format(FormattedExcinfo.fail_marker,
|
||||||
prefix = 'E '
|
lines[0].strip()), red=True)
|
||||||
else:
|
for line in lines[1:]:
|
||||||
prefix = ' '
|
tw.line('{0} {1}'.format(FormattedExcinfo.flow_marker,
|
||||||
tw.line(prefix + line.strip(), red=True)
|
line.strip()), red=True)
|
||||||
tw.line()
|
tw.line()
|
||||||
tw.line("%s:%d" % (self.filename, self.firstlineno+1))
|
tw.line("%s:%d" % (self.filename, self.firstlineno+1))
|
||||||
|
|
||||||
|
|
||||||
class FixtureManager:
|
class FixtureManager:
|
||||||
"""
|
"""
|
||||||
pytest fixtures definitions and information is stored and managed
|
pytest fixtures definitions and information is stored and managed
|
||||||
|
|
|
@ -395,10 +395,11 @@ class TestFillFixtures:
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*ERROR*test_lookup_error*",
|
"*ERROR at setup of test_lookup_error*",
|
||||||
"*def test_lookup_error(unknown):*",
|
" def test_lookup_error(unknown):*",
|
||||||
"*fixture*unknown*not found*",
|
"E fixture 'unknown' not found",
|
||||||
"*available fixtures*",
|
"> available fixtures:*",
|
||||||
|
"> use 'py*test --fixtures *' for help on them.",
|
||||||
"*1 error*",
|
"*1 error*",
|
||||||
])
|
])
|
||||||
assert "INTERNAL" not in result.stdout.str()
|
assert "INTERNAL" not in result.stdout.str()
|
||||||
|
|
Loading…
Reference in New Issue