[py-svn] pytest commit d31c01dbd371: fix #128 show tracebacks for all failures and errors that haven't beed PDB-debugged

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Tue Nov 23 16:11:20 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User holger krekel <holger at merlinux.eu>
# Date 1290525047 -3600
# Node ID d31c01dbd371b5a99b25eee092812a0494dc2e49
# Parent  a864bc3f8b16d5d0895d5b093e202aed4652edfd
fix #128 show tracebacks for all failures and errors that haven't beed PDB-debugged

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,7 @@ Changes between 1.3.4 and 2.0.0dev0
   is removed).
 - add a new "-q" option which decreases verbosity and prints a more
   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
   PDB during the running of tests even if capturing is ongoing.
 - fix issue123 - new "python -m py.test" invocation for py.test

--- a/_pytest/runner.py
+++ b/_pytest/runner.py
@@ -358,7 +358,9 @@ def skip(msg=""):
 skip.Exception = Skipped
 
 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
     raise Failed(msg=msg, pytrace=pytrace)
 fail.Exception = Failed

--- a/_pytest/terminal.py
+++ b/_pytest/terminal.py
@@ -332,13 +332,21 @@ class TerminalReporter:
     #
     # 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):
-        tbstyle = self.config.option.tbstyle
-        if 'failed' in self.stats and tbstyle != "no":
+        if self.config.option.tbstyle != "no":
+            reports = self.getreports('failed')
+            if not reports:
+                return
             self.write_sep("=", "FAILURES")
-            for rep in self.stats['failed']:
-                if tbstyle == "line":
+            for rep in reports:
+                if self.config.option.tbstyle == "line":
                     line = self._getcrashline(rep)
                     self.write_line(line)
                 else:
@@ -347,7 +355,10 @@ class TerminalReporter:
                     rep.toterminal(self._tw)
 
     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")
             for rep in self.stats['error']:
                 msg = self._getfailureheadline(rep)

--- a/testing/test_pdb.py
+++ b/testing/test_pdb.py
@@ -143,3 +143,11 @@ class TestPDB:
         child.expect("x = 5")
         child.sendeof()
         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*",
+        ])

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

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

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



More information about the pytest-commit mailing list