django 测试的加载装置

发布于 2024-08-20 19:18:45 字数 371 浏览 3 评论 0原文

我想在测试中使用一些装置。

我有 cms_sample 应用程序和一个固定装置文件夹,其中包含:cms_sample_data.xml

我在 test.py 中使用以下内容:

class Functionality(TestCase): 
    fixtures = ['cms_sample_data'] 

使用 django.testsTestCase 而不是 unittest

但夹具未加载。我缺少什么?

I want to use some fixtures in my tests.

I have cms_sample app and a fixtures folder inside with: cms_sample_data.xml

I use the following in my test.py:

class Functionality(TestCase): 
    fixtures = ['cms_sample_data'] 

I do use TestCase of django.tests and not unittest.

But the fixtures are not loaded. What am I missing?

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

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

发布评论

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

评论(4

谜兔 2024-08-27 19:18:45

忘记了 xml 扩展名?

class Functionality(TestCase): fixtures = ['cms_sample_data.xml']

Forgot the xml-extension?

class Functionality(TestCase): fixtures = ['cms_sample_data.xml']
笔落惊风雨 2024-08-27 19:18:45

也许您的 cms_sample_data 文件有错误。
你可以使用这个命令:
manage.py loaddata cms_sample_data

来检查该文件。

perhaps your cms_sample_data file is error.
you can use this comand:
manage.py loaddata cms_sample_data

to check the file.

久隐师 2024-08-27 19:18:45

我在 Django 文档上学习这个主题时遇到了类似的问题。我解决这个问题的方法是将存储我的夹具的格式文件更改为正确的格式。最初,我保存的夹具是一个名为“test_db.json”的普通文本文件。意识到这一点后,我将“.txt”文件更改为“.JSON”文件。当我输入“./manage.py test”命令时,它开始自行加载夹具。

I had a similar problem while learning about this subject on Django's docs. How I solved it was changing the format file that stored my fixture to the proper format. Originally, I saved the fixture was an ordinary text file with the name "test_db.json". Once I realized this, I changed the ".txt" file into a ".JSON" file. It began to load the fixture on its own once I typed in the "./manage.py test" command.

卸妝后依然美 2024-08-27 19:18:45

您使用多个数据库吗?如果是这样,您的测试可能需要设置 multi_db 属性:

multi_db = True

Are you using multiple databases? If so, your test might need to set the multi_db property:

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