From 233baecd2dee3f3098edfaec3b21f16443d2d60c Mon Sep 17 00:00:00 2001 From: Maciej Fijalkowski Date: Wed, 24 Nov 2010 14:54:56 +0200 Subject: [PATCH] A test for trial --- _pytest/unittest.py | 6 ++++-- testing/test_unittest.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/_pytest/unittest.py b/_pytest/unittest.py index 35367e7b0..8df26be5f 100644 --- 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, __multicall__): 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: diff --git a/testing/test_unittest.py b/testing/test_unittest.py index 76eb31741..c1f40ea88 100644 --- 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