如何在 Django 测试运行中检查数据库?
我正在努力成为一名优秀的程序员并使用 Django 的测试工具。一切进展顺利,但我希望当我在调试器中停止程序时能够检查数据库。看起来我在设置例程中执行的数据库工作包含在事务中,因此我无法从另一个会话中看到它(我正在使用 PostgreSQL 后端)。
我已经做了一些尝试,但我没有安装 TransactionMiddleware。我尝试用 django.db.transactions.commit_on_success 装饰我的函数,但这没有帮助。
有什么想法吗?
I'm trying to be a good programmer and use Django's testing facility. things are going pretty well, but I would like to be able to examine the database when I stop the program in the debugger. It looks like the database work that I do in my setUp routines is wrapped in a transaction, so I can't see it from another session (I'm using a PostgreSQL back-end).
I've done some playing around and I don't have TransactionMiddleware installed. I tried decorating my functions with django.db.transactions.commit_on_success, but that is not helping.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能使用 TransactionTestCase 而不是 TestCase 可能会有所帮助。
Possibly using TransactionTestCase instead of TestCase might help.
如果您使用的是 django.test.TestCase,Django 将每个测试包装在一个事务中,该事务在测试结束时回滚。您应该改为子类化
TransactionTestCase
。If you're using
django.test.TestCase
, Django wraps each test in a transaction, which is rolled back at the end of the test. You should subclassTransactionTestCase
instead.