Pytest 索引错误:元组索引超出范围
目前我正在尝试用pytest配置我的Django REST API。当我在测试中使用带有@pytest.mark.django_db
的模型时,出现了一个错误,提示tuple index out of range
,尽管我在测试案例中并没有提到任何元组。但是,当我不进行任何数据库查询或者不使用@pytest.mark.django_db
时,一切都正常。
import pytest
from report_tenant.models import VisualModelTableColumn
@pytest.mark.django_db
def test_visual_model_table_column_table():
col = Model.objects.create(key_1=1, key_2=1, key_5=1, key_3=1, key_4=1)
assert True == True
1 个回答
0
我把我的 conftest 文件改名成了 confest。改名之后问题就解决了。
总结:如果有人在使用 pytest 时遇到数据库连接的问题,检查一下 conftest 文件很可能就能解决你的问题。