How to stop Pycharm from running Doctests in Right Click Menu

I'm used to being able to right click in the file and clicking “Run ‘filename.py’” to run the file. However when I added doctests to a function it instead autogenerates “Run ‘Doctests in funcname’” when right clicking outside of the ‘if __name__ == “__main__”’ block.

How do I disable this feature?

0
8 comments
Hello, 
Please check the run configuration for this file (Run | Edit Configurations), take a screenshot, and attach it to this thread. Also, please upload a sample of your file here and tell us the upload ID so we can check it: https://uploads.services.jetbrains.com/
0

I have the same issue. When I right click on the file name I just have Run Doctest… and Debug Doctest...  I have Pycharm 2023.2 Community.

The screenshot of (Run | Edit Configurations) is here

Upload id: 2024_04_12_vXkKHN6Fi9BbXb2sFAGaSi (file: PycharmDoctest.png)

Is there a way to run the file with Alt-Shift-X as I would run if I did not have doctests in the doc strings?

0

Hi Arpad Horvath ! Is there any particular reason to use 2023.2 version? Does it behave the same way on the latest 2024.1 release? If so, would you please provide a minimal project sample to reproduce the issue? Please upload it to FTP and let me know the ID.

0

Hi,

Same here, PyCharm 2024.1, file on FTP under ID 2024_05_03_ETKKTi6D5mburKSphaFFBN but I'll put the code here too for the other users : 

def double(x):
    """
    >>> a = 11
    >>> print(double(a))
    22
    """
    return 2 * x

def other_function():
    print("hello")

if __name__ == '__main__':
    number = 10
    new_number = double(number)
    print(new_number)

 

If you right-click anywhere outside of the __main__ block, it will propose to run Doctest. If you right-click inside the __main__ block, it will propose to run regular Python. 

The bothering things are as follows : 

- The two propositions are linked to the same hotkeys, meaning you cannot link one hotkey for Doctest, one for Python, both are the hotkey for run. You have to place your cursor, inside __main__ block then use your hotkey to use regular Python.

- I've seen that a common answer was to edit “Run Configuration”, but I think it means creating a Running Configuration for every files you ever want to run with regular Python, and I can have hundreds of them. 

My suggestion would be to : either run Doctest only and only if your cursor is inside a function Doctest block, or always run regular Python as a default behavior.

Do you know if a plugin is able to separate these two types of run to have two different hotkeys for them ?

1

Hi David Traparic , you can select Run | Run (Alt+Shift+F10) from the menu and choose what needs to be run - python or Doctest. Does it help?

0

Hi, I didn't know this hotkey, thank you, it does indeed simplify things.

David T.

0

Hello, this is kinda dead post, but did this change somehow?

I kinda did endup running the code in terminal because I used it rarely, but lately I got to refactoring of some project and I usually want to run really quick something in the files to verify what it does or if it does it correctly after changes. Simply I just want to run a file as fast as possible, and the changes are e.g. in 5 files at the same time. All of them have tests in docstrings (now).

Considering the `Current file` is the best approach, but I can't because it does run dosctring tests instead of the script. Ok, so I do right click the file, but the `Run “whatever.py”` is not there, only `Docstring “whatever.py”`.

Why don't keep the Run action in the menu, it would not hurt, or? I would also really like if the `Current file` would have an option to not run dosctring but the file as is. Even if there is `test` in the filename, you can have test as real logic in the product, it does not have to be really a "test of code". It is good that it does predict what I want to do, but there should be an off switch if I don't want things to happen how were predicted.

0

Hi Jakub

 

Currently the advice from Mikhail would be the best option: from main menu Run → Run → select if you want to run the script of docstring tests

There is an old issue regarding this but it is not fixed:

https://youtrack.jetbrains.com/issue/PY-75057/Using-doctest-format-in-docstring-defaults-run-configuration-of-a-file-to-Doctest

 

Kind regards,

0

Please sign in to leave a comment.