python “TypeError: object() takes no parameters”问题,求大神帮忙看看
calculator.pyclassCount:def__int__(self,a,b):self.a=int(a)self.b=int(b)defadd(self):r...
calculator.py
class Count:
def __int__(self,a,b):
self.a = int(a)
self.b = int(b)
def add(self):
return self.a + self.b
test.py
from calculator import Count
#测试两个整数相加
class TestCount:
def test_add(self):
try:
j = Count(2,3)
add = j.add()
assert (add == 5),'test'
except AssertionError as msg:
print(msg)
else:
print("Test Pass!")
#执行测试类的测试方法
mytest = TestCount()
mytest.test_add()
错误提示信息:
Traceback (most recent call last):
File "E:\Python_Project\unittest\test.py", line 20, in <module>
mytest.test_add()
File "E:\Python_Project\unittest\test.py", line 8, in test_add
j = Count(2,3)
TypeError: object() takes no parameters 展开
class Count:
def __int__(self,a,b):
self.a = int(a)
self.b = int(b)
def add(self):
return self.a + self.b
test.py
from calculator import Count
#测试两个整数相加
class TestCount:
def test_add(self):
try:
j = Count(2,3)
add = j.add()
assert (add == 5),'test'
except AssertionError as msg:
print(msg)
else:
print("Test Pass!")
#执行测试类的测试方法
mytest = TestCount()
mytest.test_add()
错误提示信息:
Traceback (most recent call last):
File "E:\Python_Project\unittest\test.py", line 20, in <module>
mytest.test_add()
File "E:\Python_Project\unittest\test.py", line 8, in test_add
j = Count(2,3)
TypeError: object() takes no parameters 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询