Django_nose 不加载基本设备,例如 django_site example.com 条目或管理权限

发布于 2024-11-28 02:54:39 字数 1547 浏览 2 评论 0原文

使用当前稳定的 django_nose (0.1.3),模型甚至无法正确找到和加载,运行测试时出现以下异常:

django.db.utils.DatabaseError: (1146, "Table 'test_appdatabase.django_site' doesn't exist")

使用 git 版本的 django_nose 我设法将模型创建到测试数据库中正确地,但是它们都是空的,使用 Django 的 testrunner,我将一些基本数据加载到表中,例如 django_site 和 auth_permission 表:

django_site
id      domain  name
1       example.com     example.com

当我使用以下命令运行测试套件时安装并设置 django_nose 后,出现以下异常:

DoesNotExist: Site matching query does not exist.

有什么想法吗?


更新:使用 -v 2 运行,似乎正在为应用程序运行同步后处理程序(syncdb),

Running post-sync handlers for application sites
Creating example.com Site object
Adding content type 'sites | site'
Adding permission 'sites | site | Can add site'
Adding permission 'sites | site | Can change site'
Adding permission 'sites | site | Can delete site'

因此它似乎正在添加它们,但在某个地方它们正在被删除。


进一步更新:

查看 MySQL 查询日志,事件顺序是

  1. 在测试数据库上执行同步数据库
  2. 截断每个表(为什么?,这就是我的问题所在)
  3. 运行测试

查询日志中的截断示例:

TRUNCATE `django_site`

为什么是表被截断?是为了让测试不会互相污染,有办法禁用它吗?


我相信这是最后的更新:

使用标准 django 运行程序,会发生同样的事情,

  1. 创建表
  2. 后同步插入数据
  3. 表被截断调用
  4. Alter table 来设置 AUTO_INCRMENT = 1

除了下一步:

  1. Data被插回

    INSERT INTO django_site (domain, name) VALUES ('example.com', 'example.com')

不确定为什么这个发生在这里,但不是 django_nose

With the current stable django_nose (0.1.3) the models aren't even properly found and loaded, I get the following exception when running the tests:

django.db.utils.DatabaseError: (1146, "Table 'test_appdatabase.django_site' doesn't exist")

using the git version of django_nose I managed to get my models to be created into the test database properly, however they are all empty, with Django's testrunner I get some basic data loaded into the tables, such as the django_site and auth_permission tables:

django_site
id      domain  name
1       example.com     example.com

When I run the test suite with django_nose installed and setup, I get the following exception:

DoesNotExist: Site matching query does not exist.

Any Ideas?


Update: running with -v 2, it seems it is running the post-sync handlers (syncdb) for the applications

Running post-sync handlers for application sites
Creating example.com Site object
Adding content type 'sites | site'
Adding permission 'sites | site | Can add site'
Adding permission 'sites | site | Can change site'
Adding permission 'sites | site | Can delete site'

So it seems to be adding them, yet somewhere they are being deleted.


Further Update:

Looking at the MySQL Query log, the sequence of events is

  1. Do a syncdb on the test database
  2. Truncate every single table (why?, this is where my issue is)
  3. Run the tests

An example truncation from the query log:

TRUNCATE `django_site`

Why are the tables being truncated? Is it so that the tests don't pollute each other, is there a way to disable that?


I believe this to be the final update:

using the standard django runner, the same thing happens,

  1. tables are created
  2. post-sync inserts data
  3. the tables are truncated
  4. Alter table called to set AUTO_INCREMENT = 1

Except for the next step:

  1. Data is inserted back in

    INSERT INTO django_site (domain, name) VALUES ('example.com', 'example.com')

Not sure why this is happening here but not with django_nose

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苦行僧 2024-12-05 02:54:39
  1. 您的 INSTALLED_APPS 中是否有 sites 应用?鼻子测试运行程序扩展了 django 的测试运行程序,它应该调用 syncdb 并获取所有已安装的应用程序。
  2. 您的测试用例是什么样的? django-nose 不负责加载你的装置(普通的 Django 测试运行器也不负责)。夹具由 django.test.TestCase 加载。

编辑:
您描述的所有事情都发生在 Django 测试用例的 _fixture_setup() 中。截断等发生在flush中,然后装置被设置。

https://github.com/django/django/blob /master/django/test/testcases.py#L258

  1. Is the sites app in your INSTALLED_APPS? The nose test runner extends django's test runner, which should be calling syncdb and picking up all your installed apps.
  2. What does your test case look like? django-nose is not responsible for loading your fixtures (neither is the normal Django test runner). Fixtures get loaded by django.test.TestCase.

Edit:
All the things you're describing happen in _fixture_setup() from Django's TestCase. The truncate and such happens in flush and then the fixtures get set up.

https://github.com/django/django/blob/master/django/test/testcases.py#L258

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文