【发布时间】:2018-07-05 14:50:36
【问题描述】:
我知道之前有人问过这个question,但我想看看是否有更新的解决方案。有没有办法在setUp 中加载我的所有灯具,并在所有测试完成后刷新它们?
现在,我正在加载我的固定装置......
from django.test import TestCase
from django.core.management import call_command
class GlobalSetup(TestCase):
def setUp(self):
# Load fixtures
call_command('loaddata', 'test_cfst.json', verbosity=0)
call_command('loaddata', 'test_lmt.json', verbosity=0)
call_command('loaddata', 'test_qt.json', verbosity=0)
class BaseTest(GlobalSetup):
fixtures = [
'test_cfst.json',
'test_lmt.json',
'test_qt.json'
]
def setUp(self):
super(BaseTest, self).setUp()
def test_base(self):
# Some random tests
使用较新版本的 django 是否有办法或更好的方法来做到这一点?
【问题讨论】:
-
This answer 对您的链接问题说,自 Django 1.8 以来,每个测试类都会加载一次固定装置。
-
啊,我浏览了 1.8 更新,但我略过了TestCase 部分。没有三重检查是我的错。感谢您指出。
标签: python django django-tests