Pycharm won't allow to run a file. Shows run unittest option only.

Viewed 15259

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.

6 Answers

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:

enter image description here

Or you can also run the script, in bash console by python just_test.py.

enter image description here

I had the same problem, deleted my .idea folder in the directory of the project I was working on and was able to run my tests normally again:

PyCharm 2018.2.4 (Community Edition)
Build #PC-182.4505.26, built on September 19, 2018
JRE: 1.8.0_152-release-1248-b8 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

P.S. You can your version of PyCharm by going to Help -> About

Related