简体   繁体   中英

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.

在此处输入图片说明

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.

In your configuration, set:

  • Target to the relative path of one of your test files, ie 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 (ie 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.

An alternative is adding --no-cov --capture=no into Additional Arguments . To make this automatic for other test file, add those into the Template part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM