Tia*_*Liu 5 postgresql unit-testing flask flask-sqlalchemy flask-testing
我正在使用 Flask-testing 对 Postgres 应用程序进行一些单元测试。根据文档,我有以下代码。
from flask_testing import TestCase
from src.game.models import db
from src import create_app
class BaseTest(TestCase):
SQLALCHEMY_DATABASE_URI = 'postgresql://demo:demo@postgres:5432/test_db'
TESTING = True
def create_app(self):
# pass in test configuration
return create_app(self)
def setUp(self):
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
Run Code Online (Sandbox Code Playgroud)
当然我得到了这个错误
sqlalchemy.exc.OperationalError:(psycopg2.OperationalError)致命:数据库“test_db”不存在
我确实有一个数据库postgresql://demo:demo@postgres:5432/demo,它是我的生产数据库。
我如何test_db在这BaseTest堂课上进行创作?我正在使用Python 3.6和最新的flask和flask-sqlalchemy。非常感谢。
| 归档时间: |
|
| 查看次数: |
1543 次 |
| 最近记录: |