[py-svn] pytest commit 48c7827675cc: A test for trial

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Wed Nov 24 14:35:55 CET 2010


# HG changeset patch -- Bitbucket.org
# Project pytest
# URL http://bitbucket.org/hpk42/pytest/overview
# User Maciej Fijalkowski <fijall at gmail.com>
# Date 1290603296 -7200
# Node ID 48c7827675cc8159dd86b71aee4c29fbb8e20cd5
# Parent  22f3981d50c80bea055c39d0e1310dc45e0d5f75
A test for trial

--- a/_pytest/unittest.py
+++ b/_pytest/unittest.py
@@ -1,6 +1,6 @@
 """ discovery and running of std-library "unittest" style tests. """
 import pytest, py
-import sys
+import sys, pdb
 
 def pytest_pycollect_makeitem(collector, name, obj):
     unittest = sys.modules.get('unittest')
@@ -96,7 +96,9 @@ def pytest_runtest_protocol(item, __mult
                 if exc_value is None:
                     self._rawexcinfo = sys.exc_info()
                 else:
-                    self._rawexcinfo = (exc_value, exc_type, exc_tb)
+                    if exc_type is None:
+                        exc_type = type(exc_value)
+                    self._rawexcinfo = (exc_type, exc_value, exc_tb)
                 Failure__init__(self, exc_value, exc_type, exc_tb)
             ut.Failure.__init__ = excstore
             try:

--- a/testing/test_unittest.py
+++ b/testing/test_unittest.py
@@ -225,6 +225,38 @@ class TestTrialUnittest:
             "*3 skipped*2 xfail*",
         ])
 
+    def test_trial_error(self, testdir):
+        testdir.makepyfile("""
+            from twisted.trial.unittest import TestCase
+            from twisted.internet.defer import inlineCallbacks
+            from twisted.internet import reactor
+
+            class TC(TestCase):
+                def test_one(self):
+                    crash
+
+                def test_two(self):
+                    def f(_):
+                        crash
+                    
+                    return reactor.callLater(0.3, f)
+
+                def test_three(self):
+                    def f():
+                        pass # will never get called
+                    return reactor.callLater(0.3, f)
+                # will crash at teardown
+
+                def test_four(self):
+                    def f(_):
+                        reactor.callLater(0.3, f)
+                        crash
+
+                    return reactor.callLater(0.3, f)
+                # will crash both at test time and at teardown
+        """)
+        result = testdir.runpytest()
+
     def test_trial_pdb(self, testdir):
         p = testdir.makepyfile("""
             from twisted.trial import unittest



More information about the pytest-commit mailing list