I love Django and I love to create web projects that don’t need high performance. It’s a very convenient way to create an admin interface for your data or to create a REST API. I’d been working with Django until 2015 and testing was the most hated part of it. Several months ago I started to use Django again and I took some time for research and I found pytest + tox runners. Pytest framework makes it easy to write functional tests and tox is a tool for testing with the aim to automate and standardize testing in Python.
Why is writing automated tests for your application so important?
- You do not waste your time to run manual tests;
- Design of your code becomes better;
- You prove with a working test that your code works as expected;
- You can make changes in your code without worrying if something is broken or you can break it;
- It’s easy to refactor your code with tests;
Django’s official documentation has a lot of information about testing.
Following the documentation, you can find an example for unittest library, like this one: