首页 > 编程语言 > 详细

python 生成测试报告

时间:2019-06-09 00:24:52      阅读:228      评论:0      收藏:0      [点我收藏+]

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()

 

python 生成测试报告

原文:https://www.cnblogs.com/xiaozeng6/p/10992099.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!