Created
July 27, 2011 03:00
-
-
Save natduca/1108568 to your computer and use it in GitHub Desktop.
Break into pdb on unittest assertion error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest, exceptions, pdb | |
class PDBAssertionError(exceptions.AssertionError): | |
def __init__(self, *args): | |
exceptions.AssertionError.__init__(self, *args) | |
print "Assertion failed, entering PDB..." | |
if hasattr(sys, '_getframe'): | |
pdb.Pdb().set_trace(sys._getframe().f_back.f_back) | |
else: | |
pdb.set_trace() | |
unittest.TestCase.failureException = PDBAssertionError |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment