1

In django application I have a view wich runs the Celery task. Inside the celery task I do some actions with database using Django ORM.

I call my test case something like this:

class MyViewTestCase(APITestCase):
   def test_my_view(self):
       self.client.post('url',data)

my test case does all orm manupulations inside the test DB. But inside celery task all orm actions are happening on product database.

I use celery 4.

Is there option to make celery work with test django database?

1 Answers1

0

By default, Django uses an in-memory test database, which is not accessible by external process, such as Celery launched from the command line or daemon. However, it is possible to launch a worker as a thread in the Django test process with celery.contrib.testing.worker.start_worker, which will use the test database as desired.

drhagen
  • 8,331
  • 8
  • 53
  • 82