擺脫京城貴婦unittest的騷套路discover,自定義用例執行順序。
阿新 • • 發佈:2018-07-14
2.0 sdi def scrip con xxx imp .config mil
# 調試了一下午跟路徑拆分邏輯有關的東西,腦闊疼,代碼能力薄弱的一批, 還有前人栽htmltestrunner後入乘涼的感覺不要太爽
# 用TestLoader().discover()找到的用例添加進testsuite中執行順序是按照ASCII順序來搞得,所以寫了這個找固定目錄及子目錄下的所有固定格式case並自動導入
def find_case(case_path):
if os.path.exists(case_path):
script_list = os.listdir(case_path)
for script in script_list:
testScript = os.path.join(case_path,script)
if os.path.isdir(testScript):
find_case(testScript)
elif script[0:3] == "NO_" and script[-3:] == ".py":
script_dir = os.path.dirname(testScript)
script_path = ".".join(script_dir.split("\\")[2:])
path = "from "+ script_path + " import "
exec_str = path + script[:-3]
exec(exec_str, globals())
case = "%s.%s(‘%s‘)" % (script[:-3], script[:-3], "test_procedure")
case_list.append(case)
return case_list
def get_suite(case_path):
cases = find_case(case_path)
forcase in cases:
suite.addTest(eval(case))
return suite
pasting
def TestSuitRunner(rootDir=CASE_PATH,
Report_Name=‘XXX-X-V2.0 AutoTestReport.html‘,
tester=‘Mariahcat‘):
test_suite = get_suite(rootDir)
filePath = os.path.join(REPORT_PATH, Report_Name)
fp = open(filePath, ‘wb‘)
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title=Report_Name,
tester=tester
)
runner.run(test_suite)
fp.close()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/7/14 16:09
# @Author : Mariahcat
# @Desc :
from ATFactory.Common.ParameterFactory.Config import Config, CONFIG_FILE
from ATFactory.Common.ReportFactory import TestSuitFactory
config = Config(config=CONFIG_FILE)
REPORT_INFO = config.get("REPROT INFO")
test_dir = REPORT_INFO.get(‘TEST_DIR‘)
report_name = REPORT_INFO.get(‘REPORT_NAME‘)
tester = REPORT_INFO.get(‘TESTER‘)
TestSuitFactory.TestSuitRunner(rootDir=test_dir, Report_Name=report_name, tester=tester)
擺脫京城貴婦unittest的騷套路discover,自定義用例執行順序。