Unable to debug in pycharm with pytest
Solution 1:
For my situation, I found what the problem is:
If there is --cov
in pytest.ini
, then breakpoints in pycharm won't work, after deleting all --cov
in pytest.ini
, the breakpoints in pycharm can work.
Reason:
"The coverage module and pycharm's debugger use the same tracing api (sys.settrace) - they don't work together. " -- https://github.com/pytest-dev/pytest-cov/issues/131
References:
How to debug py.test in PyCharm when coverage is enabled
Solution 2:
The root issue is debugging does not work if you have coverage enabled by default (usually on pytest.ini).
To disable just on pycharm, just add --no-cov
on the Additional Arguments
on the Run/Debug Configurations
.
Update Templates -> Python tests -> pytest
, so every new test gets this configuration.
After this, delete your current debug settings and redebug it.
Pycharm 2018.3.x
(still works in 2020.x)
Solution 3:
TL;DR: Disable the "Gevent compatible" flag in the "Build, execution, Deployment" -> "Python Debugger".
It seems that at some point I enabled the "Gevent compatible" debugger in pycharm, and since then pytest-pycharm stopped working. Disabling it will make pytest-pycharm work again. I hope this will solve the issue for some of you.
Solution 4:
I know that you had it right, but for me actually setting the Default test runner to pytest
solved the problem.
In PyCharm: Settings
-> Python Integrated Tools
-> Testing section
-> Default test runner
-> choose pytest
from the dropdown menu -> Apply. And it instantly works.