pytest 3.5.0破坏了芹菜测试

时间:2018-04-02 11:33:59

标签: python django celery pytest

从3.4.2到3.5.0的pytest更新后,我的芹菜测试崩溃了,错误

Failed: Database access not allowed, use the "django_db" mark,
or the "db" or "transactional_db" fixtures to enable it.

我试图将@pytest.mark.django_db添加到我的测试中,但没有任何改变。

代码:

conftest.py:     

@pytest.fixture(scope='session')
def celery_session_app(request):
    """Session Fixture: Return app for session fixtures."""
    yield django_celery_app

@pytest.fixture(scope='session')
def celery_session_worker(request,
                      celery_session_app,  # noqa: pylint=redefined-outer-name
                      celery_worker_pool,
                      celery_worker_parameters):
    """Session Fixture: Start worker that lives throughout test suite."""
    with worker.start_worker(celery_session_app,
                         pool=celery_worker_pool,
                         **celery_worker_parameters) as worker_context:
        yield worker_context

测试:

def test_create_task(celery_session_worker):
    x = debug_task.delay()
    assert x.status in ['PENDING', 'SUCCESS']
    assert x.get(timeout=20) == "Request: '_project_.celery.debug_task'"

0 个答案:

没有答案
相关问题