Can I debug with python debugger when using py.test somehow?

前端 未结 6 702
悲&欢浪女
悲&欢浪女 2020-12-08 09:22

I am using py.test for unit testing my python program. I wish to debug my test code with the python debugger the normal way (by which I mean pdb.set_trace() in the code) but

6条回答
  •  我在风中等你
    2020-12-08 09:40

    The easiest way is using the py.test mechanism to create breakpoint

    http://pytest.org/latest/usage.html#setting-a-breakpoint-aka-set-trace

    import pytest
    def test_function():
        ...
        pytest.set_trace()    # invoke PDB debugger and tracing
    

    Or if you want pytest's debugger as a one-liner, change your import pdb; pdb.set_trace() into import pytest; pytest.set_trace()

提交回复
热议问题