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

问题描述

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

# @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(显示为注释出),我仍然会收到错误消息

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)