Pycharm won't allow to run a file. Shows run unittest option only.
Solution 1
If you right-click inside the 'if name == "main"' block, it will show you the regular "Run script" option instead of "Run unit test". After that, you can save the created run configuration and use it to run the script.
Solution 2
One detail missing from @yole’s answer is that you need to delete any existing configurations associated with the file before you can right-click and get it to run/debug. So, the full procedure is:
- Delete any existing configurations for that file by going to ‘Run -> Edit Configurations’ in the menu.
- Right click inside the
if __name__ == '__main__':
block - Choose
Run
- Save the configuration
After that, you should be able to run or debug the file as expected.
Solution 3
I couldn't get @yole's answer to work but i did manage by going to run > edit configurations > new configuration (the plus sign) > select python, now input a name (mine was 'stop the bloody unittest') and select the correct script
Solution 4
Using PyCharm Community Edition 2017.2 EAP. Here is how I did it:
- From the
Run
menu selectRun...
. (Or use its keyboard shortcut) - A popup menu appears that should contain at least three entries:
edit configuration...
,my_script_name
, andUnittests in my_script_name.py
. Click on the right arrow ofmy_script_name
. - If the configuration is not saved, you should be able to see a
save configuration
option in the arrow menu. Choose it.
If the configuration changed again, follow the same steps but this time choose run
in the last step.
Solution 5
As to me, "If you right-click inside the 'if name == "main"' block" will not work.
For example if you want to run "dlib_fun_test.py", you should ‘Edit Configurations’ , remove it from "python tests", and then add it to the above "Python".
The below is my configure:
Or you can also run the script, in bash console by python just_test.py.
VaidAbhishek
#include <Co-Founder/Researcher @Frrole> import moocs import computer.science.* require activelearning
Updated on June 02, 2022Comments
-
VaidAbhishek about 2 years
I have a file and it has bunch of methods starting with prefix "test". Now I want to run this file and it has a
__name__ == "__main__"
construct which sets it up. However, when I right click or go to run menu bar, It (Pycharm) only shows me "Run Unittests in xxx". This is very annoying behaviour.Can someone please tell me how to avoid this.