I want to use ipdb instead of pdb with py.test --pdb option. Is this possible? If so, how?
Clearly, I can use import ipdb; ipdb.set_trace()
in the code but that requires to run the test, watch it fail, open a file, find the point of failure in said file, write the above line, re-run the tests. Lots of hassle if I could have something that by passes all of that.
Using pytest to start pdb debuggerYou can use different command options like l (list), a(args), n(next) etc., after entering into pdb prompt. To quit from the pdb prompt, simply press q(quit) and the ENTER key. This will invoke the Python debugger at the start of every test. ii) Enter into PDB prompt on failures.
To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally, and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().
Just use python -m pdb <your_script>. py then b <line_number> to set the breakpoint at chosen line number (no function parentheses). Hit c to continue to your breakpoint. You can see all your breakpoints using b command by itself.
Use this option to set custom debugger:
--pdbcls=IPython.terminal.debugger:Pdb
It can also be included in pytest.ini using addopts
:
[pytest]
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"
Have you tried pytest-ipdb?
Looks like it's exactly what you are looking for?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With