Created
February 6, 2017 20:17
-
-
Save djromero/0c3c1c40e247dd14b43e03bcb5aca600 to your computer and use it in GitHub Desktop.
Debug on exceptions decorator.
This file contains hidden or 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
# http://stackoverflow.com/a/4399246/143097 | |
import unittest | |
import sys | |
import pdb | |
import functools | |
import traceback | |
def debug_on(*exceptions): | |
if not exceptions: | |
exceptions = (AssertionError, ) | |
def decorator(f): | |
@functools.wraps(f) | |
def wrapper(*args, **kwargs): | |
try: | |
return f(*args, **kwargs) | |
except exceptions: | |
info = sys.exc_info() | |
traceback.print_exception(*info) | |
pdb.post_mortem(info[2]) | |
return wrapper | |
return decorator | |
class tests(unittest.TestCase): | |
@debug_on() | |
def test_trigger_pdb(self): | |
assert False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For nosetests just: