Disable Pytest in PyCharm

14,053

Solution 1

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

Solution 2

You can either create a run configuration for that specific file, under Run/Edit Configurations, or you can change the test discovery settings for py.test, so files starting with test_* are not considered test files by default.

More information here:

http://pytest.org/2.2.4/example/pythoncollection.html

Share:
14,053
Peter
Author by

Peter

Updated on June 03, 2022

Comments

  • Peter
    Peter about 2 years

    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.