我正在使用 django-rest-framework创建 API。我正在使用框架的 APITestCase
测试我的一些端点。
文档没有指定加载夹具和传统的方式 fixtures= ['initial_data.json']
似乎没有工作。
如何装载夹具?
最佳答案
您描述的方式也应该有效。确保您在测试类中声明了夹具。下面是一个例子:
class MyViewsTestCase(APITestCase):
fixtures = ['some_testdata.json']
def test_random_thingy(self):
variable = 'hello'
self.assertEqual(variable, 'hello')
每次运行测试时,都会在测试运行后加载和删除夹具。
关于Django Rest Framework - 在 APITestCase 中加载装置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25297541/