使用 py.test 时,我有一些可以在SQLite上正常运行的测试,但是当我切换到Postgresql时却无声地挂起。我将如何调试类似的东西?我可以在其中进行测试或设置断点的详细模式吗?更一般而言,当pytest静默停止时,标准的攻击计划是什么?我尝试使用 pytest-time ,并使用$ py.test --timeout = 300运行测试,但是测试仍然挂起,屏幕上没有任何活动
While using py.test, I have some tests that run fine with SQLite but hang silently when I switch to Postgresql. How would I go about debugging something like that? Is there a "verbose" mode I can run my tests in, or set a breakpoint ? More generally, what is the standard plan of attack when pytest stalls silently? I've tried using the pytest-timeout, and ran the test with $ py.test --timeout=300, but the tests still hang with no activity on the screen whatsoever
推荐答案我遇到了与Flask和SQL Server / Postgres相同的问题SQLAlchemy,类似于Gordon Fierce。但是,我的解决方案有所不同。 Postgres对表锁和连接非常严格,因此在拆卸时显式关闭会话连接可以为我解决问题。
I ran into the same SQLite/Postgres problem with Flask and SQLAlchemy, similar to Gordon Fierce. However, my solution was different. Postgres is strict about table locks and connections, so explicitly closing the session connection on teardown solved the problem for me.
我的工作代码:
@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
更多推荐
py.test挂起时该怎么办?
发布评论