I'm writing a Django application employing the Huey task queue, configured as described in the relevant Huey docs. Running some basic tests, I disabled the immediate
setting to try the manage.py run_huey
command to run the task consumer in its own process.
I then ran a Django TestCase
that invokes a Huey task that writes to the database (which, inside a TestCase
, should be a temporary database created for and destroyed after testing.) The task was consumed in the Huey process and functioned as expected; however, the object created in the task run by the test was written to my actual (development) database.
I understand why -- whatever magic Django does to spin up a fake database when running tests just doesn't reach across to the Huey consumer process; and I understand that per the Huey docs, its default behavior is to run in immediate mode (executing tasks as soon as they are enqueued without running a scheduling database or a separate consumer process) when Django's DEBUG
setting is enabled, so I was stepping out on a limb.
However, I feel like I some of the standard Huey features that aren't available in immediate mode -- scheduling tasks to occur in the future, running weightier computations in separate threads or processes -- are things I would want to test or experiment with in development. Hence, my question: is there a good way to configure Huey with Django to accomplish this -- for TestCase's database mocking to work as intended when Huey tasks are consumed in a separate process?
(I am very new to Django, testing, pretty much all of this so I'm happy to listen to arguments that this is outside the scope of behavior I should be concerned with testing.)