import unittest
import HtmlTestRunner
import os
from Ultimatix_login import ultimatix_login1
from searchtest import searchtest
directory1=os.getcwd()
class main_test(unittest.TestCase):
def test_Issue(self):
test1=unittest.TestLoader().loadTestsFromTestCase(ultimatix_login1)
tests2=unittest.TestLoader().loadTestsFromTestCase(searchtest)
#combining both the test cases into one suite
suite=unittest.TestSuite([test1,tests2])
outfile=open(directory1,"maintest.html","w")
runner1=HtmlTestRunner.HTMLTestRunner(
output=outfile,
report_title="test_report",
descriptions="Main_test"
)
runner1.run(suite)
#opening the report file
#outfile=open(dir +"testreport.html","w")
if __name__=="__main__":
unittest.main()
我正在尝试生成 html 测试报告,但测试用例执行正常,但 html 报告没有生成,请帮助我解决这个问题。谢谢。
此行不正确:
outfile=open(directory1,"maintest.html","w")
根据内置open
函数的文档,它的前三个参数预计为
- 文件路径(字符串(
- 打开文件的模式(字符串(
- 缓冲策略(整数(
调用函数的方式是传递以下参数:
- 文件路径→
directory1
- 模式→
"maintest.html"
- 缓冲→
"w"
– 这是错误的,需要整数。
似乎您实际上想使用<directory1>maintest.html
作为文件路径,"w"
作为打开模式。
为此,请使用os.path.join
函数:
outfile = open(os.path.join(directory1, "maintest.html"), "w")
(请注意,您必须省略,无论如何,这意味着不同的东西。