python-unittest
程序员文章站
2022-06-11 17:45:49
用到的环境/工具/技术:pycharm、python、unittest、HTMLTestRunner结构示例:代码示例调度执行文件run-all-case.pyimport unittestimport os# 用例路径case_path = os.path.join(os.getcwd(), "case")# 报告存放路径report_path = os.path.join(os.getcwd(), "report")def all_case(): discover =...
1.用到的环境/工具/技术:
pycharm、python、unittest、HTMLTestRunner
2.结构示例:
3.代码示例
3.1 调度执行文件
run-all-case.py
import unittest
import os
# 用例路径
case_path = os.path.join(os.getcwd(), "case")
# 报告存放路径
report_path = os.path.join(os.getcwd(), "report")
def all_case():
discover = unittest.defaultTestLoader.discover(case_path,
pattern="test*.py",
top_level_dir=None)
print(discover)
return discover
if __name__ == "__main__":
runner = unittest.TextTestRunner()
runner.run(all_case())
3.2 case文件
import unittest
import time
class Test(unittest.TestCase):
def setUp(self):
print("start.")
def tearDown(self):
time.sleep(3)
print("end.")
def test01(self):
print("run test01.")
def test02(self):
print("run test02.")
if __name__ == '__main__':
unittest.main()
坑:
case文件的命名不能包含“中划线”
本文地址:https://blog.csdn.net/qq_37911780/article/details/107364900
上一篇: 揭秘:典韦为什么能在三国中排名第三?