1、拉取一套模版代码,生成一个templates模版
import unittest
import nnreport
def run(discover_path, scan_filename, file_title, filename):
f = unittest.defaultTestLoader.discover(discover_path, scan_filename)
f = unittest.TestSuite()
{suite}
report = nnreport.BeautifulReport(f)
report.report(file_title, filename, log_path=".")
run("{discover_path}", "{scan_filename}", "{file_title}", "{filename}")
2、模版抽取变量
在这里插入代码片
3、读取文件,替换变量,生成新的.py文件
file = open("run", "r")
wfile = open("run1.py", "w")
li = []
suit = "f.addTest()"
for line in file:
wfile.write(line.format(
discover_path=".",
scan_filename="demo1*",
file_title="autoGen",
filename="demo2",
suite=suit
))
4、执行py文件
|