1 回答

TA貢獻1846條經驗 獲得超7個贊
解決了。這是一個配置錯誤。
事實上,我在 create_app() 工廠中犯了一個錯誤。
據我所知,最好在服務器父目錄的init .py 文件中定義 create_app (我在 main.py 中定義該函數)。
需要明確的是,我將 create_app 工廠定義移至此處 (*):
.
├── api
│ ├── __init__.py *
│ ├── conf
│ ├── database
│ ├── error
│ ├── handlers
│ ├── models
│ ├── roles
│ ├── schemas
│ └── test.db
├── main.py
├── tests
│ ├── conftest.py
│ └── test_routes.py
新測試/conftest.py:
import pytest
from api import create_app
@pytest.fixture
def app():
flask_app = create_app({'TESTING': True})
yield flask_app
@pytest.fixture
def client(app):
return app.test_client()
@pytest.fixture
def runner(app):
return app.test_cli_runner()
最后,我調用python3 -m pytest最上面的文件夾 ( .) 來運行測試。
現在測試正在運行,我還可以為測試和其他用例創建不同的配置。
添加回答
舉報