Django 中是否有一个装饰器可以允许在不应用固定装置的情况下运行测试函数?
类似于:
from django.test import TestCase
class TestSomething(TestCase):
fixtures = ['test_fixture.json']
def test_with_fixture(self):
# test something with fixtures
@do_not_use_fixtures
def test_without_fixtures(self):
# test something without fixtures
最佳答案
Django 的 TestCase
为类 for performance reasons 加载一次固定装置。 。因此,没有固定装置就不可能运行测试方法。
使用 TransactionTestCase
可能是可行的,但您必须深入了解 Django 内部结构才能做到这一点,所以我不推荐它。
关于Django 装饰器在测试中跳过固定装置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49798524/