Fix email sending during tests

This commit is contained in:
Raphael Michel
2021-03-11 22:46:07 +01:00
parent b3c9dca024
commit 76e9093fea

View File

@@ -242,6 +242,11 @@ def mail(email: Union[str, Sequence[str]], subject: str, template: Union[str, La
task_chain.append(send_task) task_chain.append(send_task)
if 'locmem' in settings.EMAIL_BACKEND:
# This clause is triggered during unit tests, because transaction.on_commit never fires due to the nature
# Django's unit tests work
chain(*task_chain).apply_async()
else:
transaction.on_commit( transaction.on_commit(
lambda: chain(*task_chain).apply_async() lambda: chain(*task_chain).apply_async()
) )