I solved the problem by wrapping the imports of the test-file inside a context manager, as follow:
with patch('django.core.mail.send_mail') as mocked_send_mail: from ModuleToTest.File import functionToTest That forced the patch to occur before the tested function was actualy imported. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4212245-30cb-47e5-9505-5b66cff20064%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.