Guidance around testing, including outbox and ENQUEUE_ON_COMMIT #111
silviogutierrez
started this conversation in
General
Replies: 1 comment 2 replies
-
This is interesting, and something I've seen a little. The behaviour is different. I think the issue is that I think the only solution is to use |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm assuming like many others, I'm using this for sending emails.
Migration was super straightforward just wrapped my central
send_email
with@task
and renamed all calls tosend_email.enqueue()
. Typing worked flawlessly as did functionality.Problem is with my tests. I use
outbox
from pytest but the same issue applies tomail.outbox
in regular Django.Seems like
outbox
is not populated even ifImmediateBacked
is used when I test a view. I imagine it has something to do with the default transaction handling because all transactions are actually reverted at the end of the test for speed benefits. This is a test runner optimization. Resets the DB after every test.Flipping
ENQUEUE_ON_COMMIT
toFalse
just for tests seemed to work. But now we're introducing possible differences between live and test behavior.I think at the very least, this should be clarified. Or maybe even handled. But I suspect no tasks will run on tests by default because of the commit behavior.
Beta Was this translation helpful? Give feedback.
All reactions