python 生成测试报告


from comm.HTMLTestRunner import  HTMLTestRunner
import unittest
from config.config import  basedir
basedir =basedir
class TestLogin(unittest.TestCase):
 
    def test_login(self):
        self._testMethodDoc=self.case_name#设置用例名称
        self.url="xxxxxxxx"
        Lg.login(self.url,self.uname,self.passwd,browserType="FF")
        Lg.assert_if_true("//a[@href='/content/merchant-mana']",self.texts)
        print("test over!")
        Lg.close_Browser()

if __name__ == "__main__":
    test_dir=basedir +"\\testcase1"#执行文件路径
    suiteTest=unittest.defaultTestLoader.discover(test_dir,pattern='test_kpcenter_yibu.py')#执行的文件
    now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))#获取当前时间
    fp = open(basedir +'//result//' + now + '区块链发票-开票中心-异步-销方购方信息' + '.html', 'wb')  # 测试报告命名
    runner = HTMLTestRunner(stream=fp, title="python test result",
                                      description='this is the result:')
    runner.run(suiteTest)
    print ("result is ok")
    time.sleep(3)
    fp.close()

有多个接口生成测试报告时,使用测试套件
 if __name__=="__main__":
    suiteTest=unittest.TestSuite()
    suiteTest.addTest(TestCase(Register))  # 用例集
    now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
    fp = open('D://My//P_result//'+ now + '注册' + '.html', 'wb')  # 测试报告命名
    runner=HTMLTestRunner.HTMLTestRunner(stream=fp,title='test测试',description='在这')
    runner.run(suiteTest)
    time.sleep(3)
    fp.close()

 测试套件的使用详见: https://www.cnblogs.com/eastonliu/p/9145255.html

单个接口时

if __name__ == "__main__":
    test_dir=basedir +"\\testcase1"#执行文件路径
    suiteTest=unittest.defaultTestLoader.discover(test_dir,pattern='test_kpcenter_yibu.py')#执行的文件
    now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))#获取当前时间
    fp = open(basedir +'//result//' + now + '区块链发票-开票中心-异步-销方购方信息' + '.html', 'wb')  # 测试报告命名
    runner = HTMLTestRunner(stream=fp, title="python test result",
                                      description='this is the result:')
    runner.run(suiteTest)
    print ("result is ok")
    time.sleep(3)
    fp.close()

 

posted @ 2019-06-08 23:10  行走的小z  阅读(307)  评论(0编辑  收藏  举报