在使用 py.test 时,我有一些测试在 SQLite 上运行良好,但当我切换到 Postgresql 时静默挂起。我将如何去调试这样的东西?是否有我可以运行测试或设置断点的“详细”模式?更一般地说,当 pytest 静默停止时,标准的攻击计划是什么?我试过使用 pytest-timeout ,并使用 $ py.test --timeout=300 运行测试,但测试仍然挂起,屏幕上没有任何事件
最佳答案
我遇到了与 Flask 和 SQLAlchemy 相同的 SQLite/Postgres 问题,类似于 Gordon Fierce。但是,我的解决方案不同。 Postgres 对表锁和连接很严格,因此在拆卸时显式关闭 session 连接解决了我的问题。
我的工作代码:
@pytest.yield_fixture(scope='function')
def db(app):
# app is an instance of a flask app, _db a SQLAlchemy DB
_db.app = app
with app.app_context():
_db.create_all()
yield _db
# Explicitly close DB connection
_db.session.close()
_db.drop_all()
引用:SQLAlchemy
关于sqlite - 当 py.test 静默挂起时该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26350911/