Skip to content

Instantly share code, notes, and snippets.

@natduca
Created July 27, 2011 03:00
Show Gist options
  • Save natduca/1108568 to your computer and use it in GitHub Desktop.
Save natduca/1108568 to your computer and use it in GitHub Desktop.
Break into pdb on unittest assertion error
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