~ 1 min

Happy django devs: @override_settings

#django #tricks

Here's a small trick for happy django developers. When writing tests in Django, the "override_settings" decorator can be quite useful. This decorator allows developers to temporarily change the value of specific settings in the project during testing, which can be useful for testing different configurations or scenarios.

Yoda

Here's a simple example of it's usage:

from django.test import TestCase, override_settings

@override_settings(DEBUG=True)
class MyTestCase(TestCase):
def test_debug_mode(self):
# This test will run with DEBUG mode set to True
pass

In the example above, the test case is decorated with @override_settings(DEBUG=True), which means that the DEBUG setting will be temporarily set to True during the execution of the test. This applies not only to DEBUG but using this on DEBUG is sometimes handy to see sql queries and other things.

By the way, I write about software development, web development, and Django. If you liked this post and were wondering how to get more... Join my inner circle (aka newsletter) in easy (and fast!) 4 steps.

  1. Fill your email.
  2. Fill your name (but only if you want).
  3. Smash the button. As hard as you can.
  4. There is no 4th step.

Add your name to join my inner circle (also known as newsletter 💌)

And that's a wrap. I hope you like it (I really do). If you did, hit one of those share buttons and spread it on your socials.

Related posts

If you liked this post and want to read more, take a loot at these: