Merge pull request #6384 from pv/showlocals-short
Make --showlocals work together with --tb=short Fixes https://github.com/pytest-dev/pytest/issues/494 Ref: https://github.com/pytest-dev/pytest/issues/1715
This commit is contained in:
commit
1667cf3350
1
AUTHORS
1
AUTHORS
|
@ -210,6 +210,7 @@ Omer Hadari
|
||||||
Ondřej Súkup
|
Ondřej Súkup
|
||||||
Oscar Benjamin
|
Oscar Benjamin
|
||||||
Patrick Hayes
|
Patrick Hayes
|
||||||
|
Pauli Virtanen
|
||||||
Paweł Adamczak
|
Paweł Adamczak
|
||||||
Pedro Algarvio
|
Pedro Algarvio
|
||||||
Philipp Loose
|
Philipp Loose
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make `--showlocals` work also with `--tb=short`.
|
|
@ -786,9 +786,7 @@ class FormattedExcinfo:
|
||||||
message = excinfo and excinfo.typename or ""
|
message = excinfo and excinfo.typename or ""
|
||||||
path = self._makepath(entry.path)
|
path = self._makepath(entry.path)
|
||||||
filelocrepr = ReprFileLocation(path, entry.lineno + 1, message)
|
filelocrepr = ReprFileLocation(path, entry.lineno + 1, message)
|
||||||
localsrepr = None
|
localsrepr = self.repr_locals(entry.locals)
|
||||||
if not short:
|
|
||||||
localsrepr = self.repr_locals(entry.locals)
|
|
||||||
return ReprEntry(lines, reprargs, localsrepr, filelocrepr, style)
|
return ReprEntry(lines, reprargs, localsrepr, filelocrepr, style)
|
||||||
if excinfo:
|
if excinfo:
|
||||||
lines.extend(self.get_exconly(excinfo, indent=4))
|
lines.extend(self.get_exconly(excinfo, indent=4))
|
||||||
|
@ -1045,6 +1043,8 @@ class ReprEntry(TerminalRepr):
|
||||||
for line in self.lines:
|
for line in self.lines:
|
||||||
red = line.startswith("E ")
|
red = line.startswith("E ")
|
||||||
tw.line(line, bold=True, red=red)
|
tw.line(line, bold=True, red=red)
|
||||||
|
if self.reprlocals:
|
||||||
|
self.reprlocals.toterminal(tw, indent=" " * 8)
|
||||||
return
|
return
|
||||||
if self.reprfuncargs:
|
if self.reprfuncargs:
|
||||||
self.reprfuncargs.toterminal(tw)
|
self.reprfuncargs.toterminal(tw)
|
||||||
|
@ -1086,9 +1086,9 @@ class ReprLocals(TerminalRepr):
|
||||||
def __init__(self, lines: Sequence[str]) -> None:
|
def __init__(self, lines: Sequence[str]) -> None:
|
||||||
self.lines = lines
|
self.lines = lines
|
||||||
|
|
||||||
def toterminal(self, tw) -> None:
|
def toterminal(self, tw, indent="") -> None:
|
||||||
for line in self.lines:
|
for line in self.lines:
|
||||||
tw.line(line)
|
tw.line(indent + line)
|
||||||
|
|
||||||
|
|
||||||
class ReprFuncArgs(TerminalRepr):
|
class ReprFuncArgs(TerminalRepr):
|
||||||
|
|
|
@ -670,6 +670,26 @@ class TestTerminalFunctional:
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_showlocals_short(self, testdir):
|
||||||
|
p1 = testdir.makepyfile(
|
||||||
|
"""
|
||||||
|
def test_showlocals_short():
|
||||||
|
x = 3
|
||||||
|
y = "xxxx"
|
||||||
|
assert 0
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = testdir.runpytest(p1, "-l", "--tb=short")
|
||||||
|
result.stdout.fnmatch_lines(
|
||||||
|
[
|
||||||
|
"test_showlocals_short.py:*",
|
||||||
|
" assert 0",
|
||||||
|
"E assert 0",
|
||||||
|
" x = 3",
|
||||||
|
" y = 'xxxx'",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def verbose_testfile(self, testdir):
|
def verbose_testfile(self, testdir):
|
||||||
return testdir.makepyfile(
|
return testdir.makepyfile(
|
||||||
|
|
Loading…
Reference in New Issue