测试运行时Django测试数据库看起来空着 [英] Django test database looks empty while test is running

查看:79
本文介绍了测试运行时Django测试数据库看起来空着的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用本地PostgreSQL服务器的Django项目。
我正在使用调试器来调试一些奇怪的错误。当调试器在其中一项测试上停止时,我尝试查看测试数据库。我看到了这个新数据库(test_project1),所有方案都按应有的定义。但是所有表都是空的。

I have a Django project that uses local PostgreSQL server. I'm using a debugger to debug some weird bugs that I have. While the debugger is stopped on one of the tests, I tried to look at the test database. I see this new database (test_project1) and all the schemes are defined as they should be. But all tables are empty.

我知道这些表也不是空的:

I know that the tables are not empty:


  • 我使用了灯具和一些测试已经运行并返回了数据。

  • 后期测试创建了一个新用户并返回了201状态码。

但是,当尝试使用 pgAdmin3 psql 访问数据库时,我看不到任何数据。

And yet, I see no data when I try to access the database with pgAdmin3 or psql.

你知道这里发生了什么吗?
Django是否使用某种复杂的缓存机制?

Any idea what is going on here? Is there some kind of sophisticated cache mechanism that Django uses?

推荐答案

Django的 TestCase 在自己的事务中包装每个测试 。因此,无论何时通过ORM进行请求,都不会使用您的数据库。

Django's TestCase is wrapping every test in its own transaction. So your database is not being used any time you do a request through ORM.

这篇关于测试运行时Django测试数据库看起来空着的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆