Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idea run/debug py.test single test not the whole suite

I'm creating a python test suite (using py.test). I'm coding the tests in Idea and I don't know how to debug a single test.

enter image description here

This is my setting of the debugger. It runs the whole testsuite. So I have to run all the tests before it gets to the one I'm trying to debug.

like image 836
Adam Novakovi Avatar asked Apr 19 '16 12:04

Adam Novakovi


People also ask

How do I run a single test case in IntelliJ?

Rerun a single testRight-click a test on the Test Runner tab of the Run tool window and select Run 'test name'.

How do I run a single test case in PyCharm?

PyCharm makes it easy to select just one test to run. In fact, there are several ways to do it: With the cursor anywhere in the test you want to focus on, right-click and choose to run that in the test runner. Right-click on the test in the test tool listing and choose to run it.

How do I run a python test in IntelliJ?

Run all Python tests in a directoryFrom the context menu, select the corresponding run command. If the directory contains tests that belong to the different testing frameworks, select the configuration to be used. For example, select Run 'All tests in: <directory name>' Run pytest in <directory name>'.


Video Answer


1 Answers

In your configuration, set:

  • Target to the relative path of one of your test files, i.e. testsuite/psa/test_psa_integration.py
  • Keywords to a keyword that identifies the test you are trying to run specifically. If tests are part of a class, Keywords should be something like: TestPsaIntegration and test_psa_integration_example

I don't use IntelliJ, but in PyCharm, you can easily debug tests without going through this tedious process of adding a Run/Debug configuration each time.

To do this with PyCharm, go to: Preferences (or Settings) > Tools > Python Integrated Tools and set Default test runner to py.test.

Then, back in your file (i.e. test_psa_integration.py), you could just right-click anywhere within the code of a test, and select either Run 'py.test in ...' or Debug 'py.test in...' which will automatically create a new Run/Debug configuration as explained previously.

like image 165
HEADLESS_0NE Avatar answered Oct 18 '22 00:10

HEADLESS_0NE