Python Unit Testing: Automatically Running the Debugger when a test fails

前端 未结 6 1764
日久生厌
日久生厌 2020-12-02 08:24

Is there a way to automatically start the debugger at the point at which a unittest fails?

Right now I am just using pdb.set_trace() manually, but this is very tedio

6条回答
  •  既然无缘
    2020-12-02 09:02

    To apply @cmcginty's answer to the successor nose 2 (recommended by nose available on Debian-based systems via apt-get install nose2), you can drop into the debugger on failures and errors by calling

    nose2
    

    in your test directory.

    For this, you need to have a suitable .unittest.cfg in your home directory or unittest.cfg in the project directory; it needs to contain the lines

    [debugger]
    always-on = True
    errors-only = False
    

提交回复
热议问题