unittest

 

 

import requests
import random
from openpyxl import workbook, load_workbook


class MytestCase(unittest.TestCase):


    def setUp(cls) -> None:
        pass

    def tearDown(self) -> None:
        pass

    @classmethod
    def setUpClass(cls) -> None:
        workbook = load_workbook('my.xlsx', read_only=True, data_only=True)
        sheet = workbook["Sheet"]

    @classmethod
    def tearDownClass(cls) -> None:
        pass

 

suite 用法

unittest
if __name__ == '__main__':
    # unittest.main()

    suite = unittest.TestSuite()
    # 使用suite套件按照添加的顺序执行
    suite.addTest(shoppingCar("test_3_post"))
    suite.addTest(shoppingCar("test_4_get"))
    # 使用addTests
    # cases = [shoppingCar("test_4_get"),shoppingCar("test_3_post")]
    # suite.addTests(cases)

    runner=unittest.TextTestRunner()
    runner.run(suite)
suite

 

discover

unittest
import unittest
from HTMLTestRunner import HTMLTestRunner
import time

case_path = r"D:\showCode\python\Show\GoodCode\api\wind\excel"
dis = unittest.defaultTestLoader.discover(start_dir=case_path, pattern="excel*.py")  # pattern 匹配规则
print(dis)

if __name__ == '__main__':
    # runner=unittest.TextTestRunner()
    # runner.run(dis)
    # now = time.strftime("%Y-%m-%s %H:%M:%S")
    reportName = "D://report.html "
    dir = open(reportName,"wb")
    runner = HTMLTestRunner(stream=dir,title="TestReport",tester="灵感",description="用例执行明细如下")#description 描述
    runner.run(dis)
View Code

 

上一篇:GitLab Runner部署(kubernetes环境)


下一篇:unnitest简单场景应用