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):
# 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.
If you liked this post and want to read more, take a loot at these: