Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure PyCharm to automatically and continuously run my unit tests?

Tags:

python

pycharm

I would like to have some background unit tests run automatically continuously.

Can this be done in PyCharm ?

like image 924
BlueTrin Avatar asked Feb 06 '15 11:02

BlueTrin


People also ask

How do I set the default test runner in PyCharm?

To set a test runner, press Ctrl+Alt+S to open the IDE settings and select Tools | Python Integrated Tools, and then select the target test runner from the Default test runner list.

How do I keep PyCharm running?

Right-click the Run tool window and select the Pause Output toggle in the context menu. Note that only the output will be suspended. The program execution will be continued. To resume the program output, deselect Pause Output in the context menu.

How to run all tests in PyCharm?

In pycharm 2019.2, you can simply do this to run all tests: Run > Edit Configurations > Add pytest Set options as shown in following screenshot Click on Debug (or run pytest using e.g. hotkeys Shift+Alt+F9)

How do I enable pytest in PyCharm?

Open the Settings/Preferences | Tools | Python Integrated Tools settings dialog as described in Choosing Your Testing Framework. In the Default test runner field select pytest. Click OK to save the settings. There is a PyCharm documentation: Run/Debug Configuration: pytest available as of SEP 2020.

Does PyCharm support custom test runner for Django?

For Django versions 1.1 and later, PyCharm supports custom test runner, if this test runner is a class. By default, all tests are executed one by one.

How do I create a run/debug configuration for Python unit tests?

Use this dialog to create a run/debug configuration for Python unit tests. Click one of the radio-buttons to choose the possible target.: Module name: by using a Python module name and a test class instance. Script path: by using a path to a Python file. Custom: by using an arbitrary combination of paths, modules, and test class instances.


2 Answers

This is very simple. Once you have created a run configuration for the unit tests, run them once manually. With the Run dialog open you will notice on the left hand size there are a group of icons arranged vertically. In that group is an icon with a circular arrow. Click that for the auto-run you seek. It behaves smartly. It doesn't just run continuously, but rather waits for you to make some changes in the code and for your to quiesce for a few seconds. At that point it appears you would be done with a change and the auto-repeat fires.

enter image description here

Please also see https://www.jetbrains.com/pycharm/help/rerunning-tests.html for some other great tips, such as only running failed tests.

like image 108
JFlo Avatar answered Oct 03 '22 07:10

JFlo


I am late with answer, but here is official PyCharm documentation. The delay between your change and re-run can be decreased

https://www.jetbrains.com/pycharm/guide/tips/auto-run-tests/

like image 39
paut Avatar answered Oct 03 '22 07:10

paut