gpt4 book ai didi

Python单元测试Html-test runner索引超出范围

转载 作者:行者123 更新时间:2023-12-01 02:40:03 25 4
gpt4 key购买 nike

大家好,我是自动化领域的新手,正在尝试自动化我的 ui 并为其生成 HTML 测试报告。我正在使用 Html-test 运行器。请引用以下代码:

    #invalid Password
def test1(self):
rva = signUp_invalidpassword(self.driver)
self.assertEqual("Error : Invalid password",rva)
time.sleep(6)
# self.driver.refresh()
# time.sleep(10)


#Password Mismatch
def test2(self):
rvb = signUp_passwordmismatch(self.driver)
self.assertEqual("Error : Confirm Password is not matching",rvb)
time.sleep(5)



#Signup Succesfully
def test3(self):
time.sleep(5)
rvc = signUp(self.driver)
self.assertEqual("Device Monitoring and Analysis Tool",rvc)
time.sleep(8)


#Default RF parameter
def test4(self):
rvd = SignIn(self.driver)
self.assertEqual("RSRP",rvd)
time.sleep(5)


#Default Zoom_level
def test5(self):
rve = zoomLevel(self.driver)
self.assertEqual("Zoom level: 4.0",rve)
time.sleep(5)

#Chance RF parameter
def test6(self):
rvf = changeRF(self.driver)
self.assertEqual("RSRQ",rvf)
time.sleep(4)


#Empty Search State
def test7(self):
rvg = noState(self.driver)
self.assertEqual("Please enter a search term.",rvg)
time.sleep(4)


#Polygon Functionality
def test8(self):
rvj = polygon(self.driver)
self.assertEqual("CLOSE",rvj)
if __name__=='__main__':
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='Dmat_dir'))

但我得到以下输出:

                            Generating HTML reports... 
Traceback (most recent call last):
File "C:/Users/inswadhwa/PycharmProjects/automation/assertion.py", line 99, in <module>
unittest.main(testRunner=HtmlTestRunner.HTMLTestRunner(output='Dmat_dir'))
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\unittest\main.py", line 95, in __init__
self.runTests()
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\unittest\main.py", line 256, in runTests
self.result = testRunner.run(self.test)
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\HtmlTestRunner\runner.py", line 95, in run
result.generate_reports(self)
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\HtmlTestRunner\result.py", line 339, in generate_reports
testRunner)
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\HtmlTestRunner\result.py", line 316, in _report_tests
tests = self.sort_test_list(tests)
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\HtmlTestRunner\result.py", line 303, in sort_test_list
return sorted(test_list, key=self.get_test_number)
File "C:\Users\inswadhwa\AppData\Local\Programs\Python\Python36-32\lib\site-packages\HtmlTestRunner\result.py", line 295, in get_test_number
test_number = int(test_name.split('_')[1])
IndexError: list index out of range

Process finished with exit code 1

谁能帮我解决这个问题吗?

最佳答案

尝试将所有测试的名称从 test1 更改为 test_1。从错误来看,运行者似乎假设名称中会有 _

要控制顺序,请使用测试名称,例如 test_001test_002 等。

此外,HtmlTestRunner 似乎非常基础,并不是一个很好的选择。因此寻找替代方案

关于Python单元测试Html-test runner索引超出范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45810780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com