【问题标题】:Django decorator to skip fixtures in testsDjango 装饰器在测试中跳过固定装置
【发布时间】:2018-09-22 17:21:20
【问题描述】:

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

【问题讨论】:

  • 也许test_without_fixtures 属于不同的测试用例。
  • 语义上没有

标签: django django-testing django-fixtures


【解决方案1】:

Django 的TestCase 为for performance reasons 类加载一次固定装置。因此,没有固定装置就无法运行测试方法。

TransactionTestCase 可能是可能的,但你必须深入了解 Django 内部才能做到这一点,所以我不推荐它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-29
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 2017-08-20
    相关资源
    最近更新 更多