How to run doctests

Answered

I have a number of files with embedded doctests. Their configurations are identical. Yet in some, right-clicking the file offers to

run/debug 'Doctests'

whereas in others those menu positions simply offer to

run/debug <filename>

How can I run doctests when that option isn't listed in the menu?

 

Thanks.

0
5 comments

Hi Russ,

Thank you for contacting PyCharm support.

Please see https://stackoverflow.com/questions/29240835/how-do-i-run-doctests-with-pycharm?answertab=votes#tab-top

 

If it doesn't answer your question, please provide a project sample (can be uploaded to https://uploads.services.jetbrains.com/ as zip file), if possible. Please let us know the name of the zip file afterwards.

Kind regards,

Sergey

https://www.jetbrains.com

The Drive to Develop

0

Thanks, but it didn't help.  I am trying to do something extremely simple. I opened a file called gridWorld in PyCharm. When I right-click, the only run/debug option I get are to run/debug Doctests in gridworld, not run/debug gridWorld. I was able to copy the contents of the file to another file called gridWorld2, which I could run. That's the configuration you see at the upper right. But that configuration drop down has no other options.  

 
I am able to run the file by going to terminal mode and then running 
> python gridworld.py
So why can't I do the equivalent from the standard view?
 
Copies of both gridWorld and gridWorld2 will be uploaded to your link above.
 
Thanks.
 
-- Russ
0

Oh, now I see what you mean.

It means that it currently doesn't have any other run configuration.

Please try alt+shift+f10 for Windows or ctrl+alt+r for Mac OS, select run configuration and hit Enter.

After that you can either right click the file and run it, or use corresponding buttons.

See https://www.jetbrains.com/help/pycharm/creating-and-editing-run-debug-configurations.html for more information about Run/Debug Configuration.

0

Thanks! That did it -- although I was still confused until the end.  I did alt+shift+f10 and then hit Enter. Nothing seemed to happen! So I tried it again and found that the Doctests line I just clicked was missing. Then, right clicking let me run the file.

I appreciate the help, but why make things so difficult? Also, is there some way to get the same effect as alt+shift+f10 without having to remember that key combination?

0

Yes, it can also be done from the menu by going to `Run | Run...`. You can also customise the shortcuts as you wish.

0

Please sign in to leave a comment.