Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ipdb instead of pdb with py.test --pdb option

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.

like image 335
Sardathrion - against SE abuse Avatar asked Aug 26 '16 09:08

Sardathrion - against SE abuse


People also ask

How do I use pdb pytest?

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.

How do I debug Python code using pdb?

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().

How do you set a breakpoint in Python pdb?

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.


2 Answers

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"
like image 79
uhbif19 Avatar answered Oct 22 '22 15:10

uhbif19


Have you tried pytest-ipdb?

Looks like it's exactly what you are looking for?

like image 30
Andrew Svetlov Avatar answered Oct 22 '22 14:10

Andrew Svetlov