Can PyCharm drop into debug when py.test tests fail
Asked Answered
J

3

36

When running tests with py.test there is a --pdb option to enter pdb on failure.

Is there a similar way to enter the debugger when running the same test from within PyCharm?

Jahnke answered 11/6, 2014 at 21:31 Comment(1)
Possible duplicate of Debugging pytest post mortem exceptions in pycharm/pydevPolyanthus
J
22

There is a py.test plugin, pytest-pycharm, that will halt the PyCharm debugger when a test emits an uncaught exception.

Jahnke answered 24/6, 2014 at 8:55 Comment(5)
Great! Thanks a lot! Can you give a couple of words on how it is working?.. By just being installed in Python and without any modifications to projects?Puttergill
It is enough to have it installed so that py.test finds it as a plugin an use the callback when an exception is encountered. So there is no need to modify any project apart from having it installed in the python runtime.Utrillo
Is there a way to stop on breakpoints (set in tests from within PyCharm)?Polyanthus
This doesn't seem to work when using pyenv, as it uses shell-script shims to wrap python programs such as pytest, and his means that PyCharm is not directly running a Python program, so cannot engage the debugger.Kristy
Doesn't work for me, at least not when I simply select 'Debug [mytest]'.Urbanity
S
0

Follow the steps below to setup the correct run configuration:

  1. Run > Edit Configurations...
  2. Click the '+' button to add a new configuration.
  3. Name the configuration and specify the configuration parameters below:

Script: The path to your py.test executable (find by typing which py.test)

Script Parameters: This parameter is your test case followed by the --pdb option (ie /Users/Johan/projects/misc/testing.py --pdb)

After setting up the configuration, you can run the test case from within PyCharm. If a test case fails, your PyCharm run window will show the pdb prompt.

enter image description here

Sejm answered 17/6, 2014 at 21:33 Comment(2)
Maybe I was not clear enough in my question, but I was hoping for a way to enter the PyCharm debugger on failure. But this answer is still better than nothing.Utrillo
In PyCharm 2016.2, I see "entering PDB" in the Run window, and I can type text (echoes in green), but it does not seem to be an active pdb prompt.Kristy
H
0

If breakpoints work, but just drop into debug does not happen, check
File > Settings > Build, Execution, Deployment > Python Debugger > Drop into debugger on failed tests.

Hasidism answered 5/7, 2024 at 20:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.