I'm using Django 1.9
and django.test
for my unit test.
This is my code for testing signals
:
@receiver(post_save, sender=EmailNotification, dispatch_uid="spacegraphy")
def post_save_notification(sender, instance, created, **kwargs):
if created:
if settings.DEBUG:
print("post_save: created!!!")
else:
instance.send_notification()
When I run this application in local, it run as development mode, which shows print(settings.DEBUG)
as True
. (I checked it in shell_plus
of django-extension
However, when I test my unit tests, print(settings.DEBUG)
show False
.
I have no idea why it happened. Any idea, please?
From https://docs.djangoproject.com/en/1.10/topics/testing/overview/#other-test-conditions:
I would suggest you write your test differently. The purpose is to test the functionality of the code as it would run in production, so there should be no need to check the value of
DEBUG
.