我在创建测试数据库时遇到问题,并且由于找不到数据库而出错。我真的不确定出了什么问题以及为什么没有创建数据库
pytest.ini
[pytest]
DJANGO_SETTINGS_MODULE=testing.test_settings
addopts = --nomigrations --cov=. --cov-report=html
test_settings.py
from settings import *
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3_testing'),
}
}
在我的测试中,我运行命令,py.test --reuse-db
但我仍然没有找到创建的 db
测试.py
@pytest.mark.django_db
class TestUsers:
def test_user(self,client):
response = client.get("/test", follow=True)
assert len(response.context['list'])==1
创建测试数据库的任何帮助都会有所帮助