我在单元测试中遇到问题,我不知道为什么,我正在进行以下堆栈:
Traceback (most recent call last):
File "novaapiclient_tests.py", line 11, in test_create_server
nova = novaapiclient.NovaAPIClient()
TypeError: __init__() takes exactly 2 arguments (1 given)
按照我的测试代码:
class TestFunction(unittest.TestCase):
def setUp(self):
self.nova = novaapiclient.NovaAPIClient()
def test_create_server(self):
self.setUp()
lsbf = self.nova.lst_of_servers(self.nova.listServers())
image = "3f9e6696-2ed2-4e06-ae16-c828062addbe"
flavor = "m1.tiny"
name = "testing_unit"
self.nova.createServer(image, flavor, name)
time.sleep(60)
lsaf = self.nova.lst_of_servers(self.nova.listServers())
if(len(lsbf) < len(lsaf)):
assertTrue(True)
else:
assertTrue(False)
def delete_server(self):
self.setUp()
serv_id = "13e0c3de-d736-47ec-bc22-3a794aa3e2a9"
self.nova.deleteServer(serv_id)
ls = self.nova.lst_of_servers(self.nova.listServers())
j = 0
fin = False
while(j < 3 and not fin):
time.sleep(75)
for i in range(len(ls)):
if(serv_id == str(ls[i])):
assertTrue(False)
break
assertTrue(True)
fin = True
break
j += 1
我尝试创建一个init方法并在方法中剪切“self”,但我继续打印错误。
答案 0 :(得分:5)
novaapiclient.NovaAPIClient
构造函数需要接收一个参数,但是你没有传递任何参数。
在this question你的{{3}}你确实将一个论点传递给novaapiclient.NovaAPIClient
,所以我假设你需要做类似的事情。