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
6 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

Please sign in to leave a comment.