在 django 中管理装置的正确方法
今天我和同事讨论了如何在 django 应用程序中管理设备。我们找不到任何能让所有人满意的解决方案,所以我在这里问这个问题。
假设我们有一个相当大的 django 项目,里面有十几个应用程序,每个应用程序都有包含几个 TestClass 的tests.py 文件。有了这个,我应该如何管理所有这些应用程序的测试数据? 从我的角度来看,有两种不同的方法:
- 为每个应用程序 test_data.json 文件单独存储所有数据。该文件将包含应用程序的 models.py 文件中定义的所有模型的测试数据,无论该数据在何处使用(它可以在不同应用程序的测试中使用)
- 存储一些常用数据test_data.json 中的所有测试(例如 auth.users)以及单独的 test_case.json 文件中每个 TestCase 的数据可能都需要。
从我的角度来看,第二种方法似乎更干净,但我想知道是否有人可以告诉我这些方法的具体优点和缺点,或者可能建议其他方法?
today I had a discussion with my colleguaes about how we should manage fixtures in our django application. We cound not find any solution that would satisfy everyone, so I'm asking this question here.
Suppose we have quite big django project with dozen of applications inside, each application has tests.py file with several TestClasses. Having this, how I should manage test data for all of these applications?
From my perpective, there is 2 different ways:
- Store all data in separate for each application test_data.json file. This file will contain test data for all models defined in the application's models.py file, irrespective of where this data is used (it can be used in tests from different application)
- Store some common data that would be probably required by all tests (like auth.users) in test_data.json and data for each TestCase in a separate test_case.json file.
From my perpective, second approach seems to be more cleaner, but I would like to know if somebody could tell me the concrete pros and cons of these approaches or may be suggest some other approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您考虑为测试定义测试数据的最简洁方法,我建议您阅读 django-任何应用程序:
此解决方案有助于避免在执行测试时在数据库中保留额外的数据。
If you think about the cleanest way to define test data for your tests, I would like to recommend you read about django-any application:
This solution is helpful for avoiding to keep extra data in you DB while your tests are executing.