Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Pytest in PyCharm

If I have a file beginning with "test_", PyCharm tries to run this with PyTest. I want to run it normally (as a regular Python script). How can I do this?

Edit See Milo's answer below. If for some reason that does not work for you, as A. Romeau pointed out, there is a way to do this on a per-file basis:

  1. For a given test file that you want to run normally:
  • Run the file... note that it runs under py.test or some other testing framework.
  • Click on the drop-down box on the top-right that says something like "py.test in test_something.py".
  • Click "Edit Configurations". This will open a window with "Python" and "Python tests" as options on the left. You'll notice you're in the "Python tests" section.
  • Copy the file path in the "Target:" field.
  • Click the red "-" in the top left, which will remove that test configuration.
  • Now, click the green "+", select "Python", and paste the file path you copied in the "Script:" field.
  • Press "OK". Your test file will now run as an ordinary script.
  1. Edit your setup.cfg file in pytest (with some option that I don't know right now) so that it doesn't "discover" your test (I have not tried this).

Neither solution is good. 1 is inconvenient because you need to go through a big mutli-click and process for each file you might want to run like this. 2 is inconvenient because it interferes with you running pytest normally, from console.

JetBrains: Please for the love of God just add an option to disable automatic unittesting. It is very annoying because the output of pytest/UnitTest is not nearly as helpful as the output of the regular interpreter when trying to track down bugs in tests (no links to the failing line, can't easily run given function alone, etc).

A PyCharm "issue" has been opened here.

like image 765
Peter Avatar asked Mar 07 '16 15:03

Peter


People also ask

How do I disable pytest case?

The simplest way to skip a test is to mark it with the skip decorator which may be passed an optional reason . It is also possible to skip imperatively during test execution or setup by calling the pytest. skip(reason) function. This is useful when it is not possible to evaluate the skip condition during import time.

What is pytest in PyCharm?

PyCharm supports pytest, a fully functional testing framework. The following features are available: The dedicated test runner. Code completion for test subject and pytest fixtures. Code navigation.

How do I stop pytest in terminal?

pytest has the option -x or --exitfirst which stops the execution of the tests instanly on first error or failed test. pytest also has the option --maxfail=num in which num indicates the number of errors or failures required to stop the execution of the tests.


1 Answers

Disable Pytest for you project

  1. Open the Settings/Preferences | Tools | Python Integrated Tools settings dialog as described in Choosing Your Testing Framework.
  2. In the Default test runner field select Unittests.
  3. Click OK to save the settings.

enter image description here

like image 60
Milo Chen Avatar answered Oct 04 '22 02:10

Milo Chen