~ 1 min
Happy django devs: @override_settings
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.
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):
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.
- Fill your email.
- Fill your name (but only if you want).
- Smash the button. As hard as you can.
- There is no 4th step.
Related posts
If you liked this post and want to read more, take a loot at these: