~ 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.

Subscribe to the newsletter

As a full-stack web developer I write about both the backend and frontend. If you liked what you read and want more, subscribe to my newsletter and I'll be sure to let you know once I release new articles.

I hope you like it! Share it with others who could enjoy it too.

Related posts

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