Make Django test case database visible to Celery

前端 未结 3 584
野性不改
野性不改 2020-12-03 05:55

When a Django test case runs, it creates an isolated test database so that database writes get rolled back when each test completes. I am trying to create an integration tes

3条回答
  •  醉话见心
    2020-12-03 06:29

    I found another workaround for the solution based on @drhagen's one:

    Call celery.contrib.testing.app.TestApp() before calling start_worker(app)

    from celery.contrib.testing.worker import start_worker
    from celery.contrib.testing.app import TestApp
    
    from myapp.tasks import app, my_task
    
    
    class TestTasks:
        def setup(self):
            TestApp()
            self.celery_worker = start_worker(app)
            self.celery_worker.__enter__()
    
        def teardown(self):
            self.celery_worker.__exit__(None, None, None)
    

提交回复
热议问题