Django测试数据库看起来空,而测试是runnin [英] Django Test Database looks empty while test is runnin

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

问题描述

我有一个使用本地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.

我知道表不为空:
- 我使用fixture和一些测试已经运行和返回的数据。
- 后测试创建新用户返回的201状态码。

I know that the tables are not empty: - I used fixture and some tests already ran and returned data. - A post test created new user returned 201 status code.

然而,当我尝试使用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 cash 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测试数据库看起来空,而测试是runnin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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