Speeding up your django tests

Running tests can become troublesome, if your tests take too long to execute. Ideally, you want an instant feedback from them. Lets us discuss some ways through which we can speed up the run time for our tests. Move data creation to setUpTestData setUpTestData is pretty much like setUpClass in unittest. This method is run once before the test class runs. One of the main reasons, tests can be slow is if data creation in done in setUp method or inside individual tests....

March 1, 2021 · 4 min

Writing unit tests for migrations in django

Writing tests for migration can be a bit tricky because all of your migrations are generally run before any of your test. In case you want to test your code for a particular migration, you will have to revert the database to that particular state. Make sure you don’t forget to revert to the latest state after this test ends. In this post, we will see who we can do this....

March 1, 2021 · 3 min

Add tests to verify registry of models to django admin

In the last post, we learned how to automate registration of models to the django-admin. In this post, we will try to see how we can add tests to verify that all our models have been registered. Why do we need it? Even though the admin.py module is run internally when running the tests, it doesn’t actually verify whether all models have been registered or not. It is a very common thing to forget registering your model to the admin, especially when you aren’t really customizing them....

July 1, 2021 · 2 min