Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 911
VaidAbhishek Avatar asked Dec 30 '13 07:12

VaidAbhishek


People also ask

How do I run a Unittest in PyCharm?

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.

How do I run a Unittest file in Python?

The command to run the tests is python -m unittest filename.py . In our case, the command to run the tests is python -m unittest test_utils.py .

How do I run Unittest tests?

If you're using the PyCharm IDE, you can run unittest or pytest by following these steps: In the Project tool window, select the tests directory. On the context menu, choose the run command for unittest . For example, choose Run 'Unittests in my Tests…'.


1 Answers

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.

like image 59
yole Avatar answered Sep 22 '22 21:09

yole