Unable to debug in pycharm with pytest

2020-05-19 03:57发布

I cannot debug in PyCharm using py.test. All the test suite is running ok in "Debug mode" but it doesn't stop on breakpoints.

Debug Mode

I also have py.test as the default test runner.

Maybe this is not important, but debugging works correctly in my Django server.

Any ideas?

Configuration picture of enable_breakpoints_and_the_mode_of_pycharm_is_debug

References:

pycharm-enabling-disabling-and-removing-breakpoints

Run/Debug Configuration: py.test

4条回答
兄弟一词,经得起流年.
2楼-- · 2020-05-19 04:17

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

查看更多
We Are One
3楼-- · 2020-05-19 04:23

What fixed for me was adding the --no-cov to the Additional Arguments on the Run/Debug Configurations. I updated the Templates -> Python tests -> pytest, so every new test gets this configuration.
Just delete your current debug settings and it will work.

enter image description here

Pycharm 2018.3.x

查看更多
冷血范
4楼-- · 2020-05-19 04:23

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.

查看更多
5楼-- · 2020-05-19 04:42

I'd like to add to this conversation that these fixes does not seem to work in the case a single test function is launched in PyCharm (rather than the whole test file).

I yet haven't found a solution online to activate breakpoints when debugging a single test function instead of the whole file, and if someone has a solution, I would be interested. If I find it myself, I'll try to update this post.

查看更多
登录 后发表回答