Python TypeError:\uuuu init\uuuu()最多接受2个参数(给定4个)
我在尝试运行django测试时收到错误消息 这是我的模型文件代码Python TypeError:\uuuu init\uuuu()最多接受2个参数(给定4个),python,django,testing,Python,Django,Testing,我在尝试运行django测试时收到错误消息 这是我的模型文件代码 class MountPoint(models.Model): name = models.CharField(max_length=100) backend = models.CharField(max_length=200,default=DEFAULT_BACKEND) path = models.CharField(max_length=300) def __
class MountPoint(models.Model):
name = models.CharField(max_length=100)
backend = models.CharField(max_length=200,default=DEFAULT_BACKEND)
path = models.CharField(max_length=300)
def __unicode__(self):
return self.name
这是我测试的课程
class MountPoint(TestCase):
def create_mountpoint(self):
name = "test"
backend = "test"
path = user_root
return MountPoint(name, backend, path)
def test_mountpoint_creation(self):
m = self.create_mountpoint()
self.assertTrue(isinstance(m, MountPoint))
self.assertEqual(m.__unicode(), m.name)
下面是我收到的错误信息。它说我有比预期更多的投入
回溯(最近一次呼叫最后一次):
文件“/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py”,第18行,在test\u mountpoint\u创建中
m=self.create_mountpoint()
文件“/Users/xihui/Documents/WebProgramming/django/ece264site/filesystem/tests.py”,第15行,在create_mountpoint中
返回装入点(名称、后端、路径)
TypeError:init()最多接受2个参数(给定4个)
在0.009s内运行1次测试
失败(错误=1)我认为您必须使用关键字args:
return MountPoint(name=name, backend=backend, path=path)
测试类的名称隐藏了模型类的名称,因此当您尝试实例化一个模型实例时,它实际上尝试创建一个测试类的新实例,这显然需要使用不同的参数。顺便说一下,将测试类重命名为
TestMountPoint
,默认值为'filesystem.BACKEND.HDWrapper.DirectionHDWrapper,filesystem.BACKEND.HDWrapper.DocumentHDWrapper'