setting breakpoints with nosetests --pdb option

前端 未结 4 619
攒了一身酷
攒了一身酷 2021-01-29 20:51

nosetests --pdb let\'s me halt upon error or failure, but this is too late for my needs. Stepping through code during execution helps me debug where the problem is.

相关标签:
4条回答
  • 2021-01-29 21:03

    Even better than remembering to use -s is to use the set_trace variant that comes with Nose. Add

    from nose.tools import set_trace; set_trace()
    

    wherever you'd like to break in to the debugger. The stdin/out redirection will be taken care of for you. The only strange side effect I've run into is the inability to restart your code from within pdb (using run) while debugging during a nose run.

    0 讨论(0)
  • 2021-01-29 21:12

    If you have ipython, for unlimited awesomeness use:

    import ipdb; ipdb.set_trace() 
    

    *unlimited awesomeness: just like ipython - auto-completion, coloring etc.

    0 讨论(0)
  • 2021-01-29 21:15

    You can add

    import pdb; pdb.set_trace() 
    

    anywhere in your source that you want to stop in the debugger.

    Make sure you pass -s to nose so that it does not capture stdout.

    0 讨论(0)
  • 2021-01-29 21:19

    If you are using pytest, you can use

    import pytest; pytest.set_trace()
    

    See documentation.

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