Decorator to enter the debugger when there’s an uncaught exception

To use, just slap a @debugger() on your function.

You may provide specific exception classes to catch as arguments to the decorator function, e.g., @debugger(RuntimeError, NotImplementedError). This defaults to just AssertionError, for use on unittest.TestCase methods.

Code provided by “Rosh Oxymoron” on StackOverflow:


Consider using pytest --pdb instead of this decorator.