Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can PyCharm drop into debug when py.test tests fail

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?

like image 780
Johan Lübcke Avatar asked Jun 11 '14 21:06

Johan Lübcke


People also ask

Can we Debug test cases?

Debug mode​ Open a test case and switch to the Script view. Double-click on the leftmost side of the script editor to mark a breakpoint. A breakpoint is where Katalon Studio pauses the test execution for you to start debugging. Choose a browser for Debug from the main toolbar.

Is Python slower in debug mode?

Unfortunately, debugger speed has some runtime limitations, which can't be easily fixed. If your code does some high performance computations, Debugger will be at least 3 times slower than usual Run. There is very low probability that this issue will be fixed soon.

What does Debug do in PyCharm?

The Debug tool window shows dedicated panes for frames, variables, and watches, and the console, where all the input and output information is displayed. If you want the console to be always visible, you can drag it to one of the PyCharm window's edges.


2 Answers

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

like image 179
Johan Lübcke Avatar answered Sep 29 '22 15:09

Johan Lübcke


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

like image 34
garnertb Avatar answered Sep 29 '22 15:09

garnertb