fix #128 show tracebacks for all failures and errors that haven't beed PDB-debugged

This commit is contained in:
holger krekel 2010-11-23 16:10:47 +01:00
parent 695bffc83d
commit 4fa7a2e8ce
7 changed files with 31 additions and 12 deletions

View File

@ -13,6 +13,7 @@ Changes between 1.3.4 and 2.0.0dev0
is removed). is removed).
- add a new "-q" option which decreases verbosity and prints a more - add a new "-q" option which decreases verbosity and prints a more
nose/unittest-style "dot" output. nose/unittest-style "dot" output.
- fix issue135 - marks now work with unittest test cases as well
- fix issue126 - introduce py.test.set_trace() to trace execution via - fix issue126 - introduce py.test.set_trace() to trace execution via
PDB during the running of tests even if capturing is ongoing. PDB during the running of tests even if capturing is ongoing.
- fix issue123 - new "python -m py.test" invocation for py.test - fix issue123 - new "python -m py.test" invocation for py.test

View File

@ -42,10 +42,6 @@ def pytest_runtest_makereport():
pytestPDB.item = None pytestPDB.item = None
class PdbInvoke: class PdbInvoke:
def pytest_sessionfinish(self, session):
# don't display failures again at the end
session.config.option.tbstyle = "no"
@pytest.mark.tryfirst @pytest.mark.tryfirst
def pytest_runtest_makereport(self, item, call, __multicall__): def pytest_runtest_makereport(self, item, call, __multicall__):
if not call.excinfo or \ if not call.excinfo or \
@ -62,6 +58,7 @@ class PdbInvoke:
rep.toterminal(tw) rep.toterminal(tw)
tw.sep(">", "entering PDB") tw.sep(">", "entering PDB")
post_mortem(call.excinfo._excinfo[2]) post_mortem(call.excinfo._excinfo[2])
rep._pdbshown = True
return rep return rep
def post_mortem(t): def post_mortem(t):

View File

@ -358,7 +358,9 @@ def skip(msg=""):
skip.Exception = Skipped skip.Exception = Skipped
def fail(msg="", pytrace=True): def fail(msg="", pytrace=True):
""" explicitely fail an currently-executing test with the given Message. """ """ explicitely fail an currently-executing test with the given Message.
if @pytrace is not True the msg represents the full failure information.
"""
__tracebackhide__ = True __tracebackhide__ = True
raise Failed(msg=msg, pytrace=pytrace) raise Failed(msg=msg, pytrace=pytrace)
fail.Exception = Failed fail.Exception = Failed

View File

@ -332,13 +332,21 @@ class TerminalReporter:
# #
# summaries for sessionfinish # summaries for sessionfinish
# #
def getreports(self, name):
l = []
for x in self.stats.get(name, []):
if not hasattr(x, '_pdbshown'):
l.append(x)
return l
def summary_failures(self): def summary_failures(self):
tbstyle = self.config.option.tbstyle if self.config.option.tbstyle != "no":
if 'failed' in self.stats and tbstyle != "no": reports = self.getreports('failed')
if not reports:
return
self.write_sep("=", "FAILURES") self.write_sep("=", "FAILURES")
for rep in self.stats['failed']: for rep in reports:
if tbstyle == "line": if self.config.option.tbstyle == "line":
line = self._getcrashline(rep) line = self._getcrashline(rep)
self.write_line(line) self.write_line(line)
else: else:
@ -347,7 +355,10 @@ class TerminalReporter:
rep.toterminal(self._tw) rep.toterminal(self._tw)
def summary_errors(self): def summary_errors(self):
if 'error' in self.stats and self.config.option.tbstyle != "no": if self.config.option.tbstyle != "no":
reports = self.getreports('error')
if not reports:
return
self.write_sep("=", "ERRORS") self.write_sep("=", "ERRORS")
for rep in self.stats['error']: for rep in self.stats['error']:
msg = self._getfailureheadline(rep) msg = self._getfailureheadline(rep)

View File

@ -5,7 +5,7 @@ see http://pytest.org for documentation and details
(c) Holger Krekel and others, 2004-2010 (c) Holger Krekel and others, 2004-2010
""" """
__version__ = '2.0.0.dev32' __version__ = '2.0.0.dev33'
__all__ = ['main'] __all__ = ['main']
from _pytest.core import main, UsageError, _preloadplugins from _pytest.core import main, UsageError, _preloadplugins

View File

@ -22,7 +22,7 @@ def main():
name='pytest', name='pytest',
description='py.test: simple powerful testing with Python', description='py.test: simple powerful testing with Python',
long_description = long_description, long_description = long_description,
version='2.0.0.dev32', version='2.0.0.dev33',
url='http://pytest.org', url='http://pytest.org',
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -143,3 +143,11 @@ class TestPDB:
child.expect("x = 5") child.expect("x = 5")
child.sendeof() child.sendeof()
child.wait() child.wait()
def test_pdb_collection_failure_is_shown(self, testdir):
p1 = testdir.makepyfile("""xxx """)
result = testdir.runpytest("--pdb", p1)
result.stdout.fnmatch_lines([
"*NameError*xxx*",
"*1 error*",
])