In the PyCharm IDE, if I right-click on a function/method with a doctest, sometimes the right-click menu will give me the option: "Run 'Doctest my_function_name'" and sometimes the right-click menu, instead, only gives the option to run the whole file (NOT as a doctest).
What determines when it will give the "run doctest" option and when it will not? Is there a way to force it one way or the other?
Choose Run | Run from the main menu or press Alt+Shift+F10 , and then select the desired run/debug configuration.
Run all tests in a directoryFrom the context menu, select the corresponding run command. If the directory contains tests that belong to the different testing frameworks, select the configuration to be used. For example, select Run pytest in <directory name>'. Explore results in the test runner.
PyCharm makes it easy to select just one test to run. In fact, there are several ways to do it: With the cursor anywhere in the test you want to focus on, right-click and choose to run that in the test runner. Right-click on the test in the test tool listing and choose to run it.
Running a module (or the tests in it) in PyCharm
is done via a Run Configuration. When you right click a module, PyCharm
searches for an existing Run Configuration
for that module. If a configuration is found (this can be due to a previous run, or a manual creation of a Configuration
), PyCharm
will only suggest to run that configuration.
For example, if a configuration of module.py
was created to run its doctests
, that is the option we'll see when right-clicking module.py
. However, if no configuration is found, PyCharm
suggests to run the module in different options, depending on the code in the module (run regularly, or run doctests
/ unittests
). Once an option is chosen, PyCharm
creates the respective, temporary, Run Configuration
, implicitly. From here on, when right clicking the module, you'll only get the configuration that was created for that module.
Important side note: PyCharm saves up to 6 temporary (i.e., Configurations
that were created via running a module) Run Configurations
- 3 in "Python", i.e., scripts, and 3 in "Python Tests". This means that if you run moduleA.py
, moduleB.py
, moduleC.py
, and then moduleD.py
, the temporary Configurations
in PyCharm will be moduleB.py
, moduleC.py
, and moduleD.py
. The configuration of moduleA.py
will be automatically deleted, unless explicitly saved.
This behaviour can be reproduced as following:
PyCharm
, create a new Python module: "temp"2.Add the following to the module:
""" >>> print 3.14 3.14 """ if __name__ == '__main__': pass
Run --> Edit configuration --> Locate the module's current configuration (usually highlighted) --> Click the "Minus" button (top left corner) --> Click "Apply" --> Click OK. Now we are back at step 3.
(Reproduced in PyCharm
5.0 and 4.5)
Run Configuration
is found, PyCharm suggests to run the module in any possible way (as a script, doctests, or unittests)Run Configuration
is found, PyCharm only suggests that Configuration
.Run Configuration
that is preventing it from giving you that option and delete it, or create a new one that will run the file, or method/function, the way you want.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With