py.test挂起时该怎么办?

编程入门 行业动态 更新时间:2024-10-23 19:31:23
本文介绍了py.test挂起时该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用 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挂起时该怎么办?

本文发布于:2023-11-16 07:38:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:挂起   py   test

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!