Get reference to the current exception

前端 未结 1 561
再見小時候
再見小時候 2021-02-13 09:46
$ ./runtests.py -v tests/managers/test_customer.py:CustomerManagerTest.test_register_without_subscription --ipdb

...

test_register_without_subscription (tests.managers         


        
1条回答
  •  感动是毒
    2021-02-13 10:08

    This has frustrated me too for a while. I eventually found the answer here, along with a good detailed explanation.

    The short answer is, use the ! magic prefix (!sys.exc_info()):

    In [4]: 1/0
    ---------------------------------------------------------------------------
    ZeroDivisionError                         Traceback (most recent call last)
    ...
    ipdb> !sys.exc_info()
    (, AttributeError("'exceptions.ZeroDivisionError' object has no attribute '_render_traceback_'",), )
    

    This basically tells the debugger: "guessing wouldn't be necessary. it is python code I'm typing", thus preventing it from trying to guess what you mean by "sys", a process during which some internal exception is raised, overwriting sys.exc_info(), which used to hold your original exception.

    0 讨论(0)
提交回复
热议问题