它不是那样工作的,你需要两个名为setup的函数来设置所需的数据(它在测试开始时运行),你需要在这里创建你的用户,然后tearDown(它在测试结束时运行)在运行测试后进行清理在添加这两个函数之后,你的代码会变成这样
class SavedModelsTestCase(TestCase):
def setUp(self):
#create your user here
def tearDown(self):
# for any clenaup required none in your case
def test_saved_models(self):
saved_model = create_saved_model()
self.assertTrue(isinstance(saved_model, SavedModels))
self.assertEqual(saved_model.name, "Test Model")
self.assertEqual(saved_model.description, "A model")
self.assertEqual(saved_model.user, user)