Do TDD nicer with PyCharm
2 min readJul 11, 2021
When developing software with the TDD method, you should run tests again and again. it will become tedious sometimes and, also you maybe forget to run a final test before commit and push. there are some automation methods to do it automatically. for example, I used git hook in PyCharm and write some small scripts to run tests before commit.
After some time I found a very useful plugin named pycrunch that automates my tests running in a very beautiful way. it is a very brief introduction to it.
Features
there is a little demo of pycrunch in action:
- show successful/failed tests
- show code coverage status and show what tests will cover the line
- show each test output
- application state tracing
start using it
- this plugin is based on a python library named: pycrunch-engine. you first should install it:
pip install pycrunch-engine
- install PyCharm plugin:
- create pycrunch config file (if it was not created):
.pycrunch-config.yaml
- fill out the pycrunch config file based on your requirements. for example, if you are using pytest, use a configuration like this:
# documentation https://pycrunch.com/docs/configuration-file
engine:
runtime: pytest
- start test daemon
- the tests will run on every save (ctrl + s) or save action that is automatically done by PyCharm.
Recommendation
- because all tests related to a test file will run on file save the event and it time-consuming if there were many tests on it, better to separate tests to multiple files.