尝试使用参数化时出现pytest.mark.django_db错误

时间:2020-08-24 15:05:38

标签: python django pytest pytest-django

我正在尝试运行以下测试:

# @pytest.mark.django_db
def create_single_shift_record() -> Response:
    data = createShiftData()
    return client.post(reverse(revLink.shifts_single), data, format='json')

@pytest.mark.django_db
@pytest.mark.parametrize(
    'dbName, createApi',
    [
        (Shifts, create_single_shift_record()),
        # Other tests from other DB's here
    ]
)
def test_create_single_record(dbName, createApi):
    res = createApi
    assert res.status_code == status.HTTP_201_CREATED
    assert dbName.objects.count() == 1

并得到错误:

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

即使我在第一个函数上方添加@pytest.mark.django_db(显示为注释出),我仍然会收到错误消息

您知道我是否能够使它正常工作,或者有另一种方法吗?

0 个答案:

没有答案