From 5c74fdb1755c4ca72a7de6679a439affb2f8e831 Mon Sep 17 00:00:00 2001 From: 20220016 <17777770016@qq.com> Date: Thu, 11 Jul 2024 19:20:35 +0800 Subject: [PATCH] ADD file via upload --- quick_runner.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 quick_runner.py diff --git a/quick_runner.py b/quick_runner.py new file mode 100644 index 0000000..df98fc8 --- /dev/null +++ b/quick_runner.py @@ -0,0 +1,72 @@ +import os, shutil +import subprocess, platform +from config.common_path import report_path +import sys, getopt + + +def clear_reports(): + if os.path.exists(report_path): + shutil.rmtree(report_path) + os.mkdir(report_path) + os.mkdir('{}{}picture'.format(report_path, os.path.sep)) + + +def main(argv): + suite_dirs = None + file_names = None + tags = None + environment = None + try: + opts, args = getopt.getopt(argv, "hd:s:t:e:x", ["help", "dir", "suite", "tag", "environment"]) + except getopt.GetoptError as e: + print(e) + print('test.py -d -s -t -e ') + sys.exit(2) + for opt, arg in opts: + if opt in ('-h', '--help'): + # print('test.py -d -s -t -e ') + sys.exit() + elif opt in ("-e", "--environment"): + environment = arg + elif opt in ("-d", "--dir"): + suite_dirs = arg + elif opt in ("-s", "--suite"): + file_names = arg.split(';') + elif opt in ("-t", "--tag"): + tags = arg + if not suite_dirs: + suite_dirs = 'smoke_test' + if not file_names: + file_names = ['**.py'] + if not tags: + tags = '' + if not environment: + environment = 'test' + return suite_dirs, file_names, tags, environment + + +if __name__ == '__main__': + clear_reports() + suite_dirs, file_names, tags, environment = main(sys.argv[1:]) + # suite_dirs = "smoke_test" + # file_names = ['*09*', '*10*'] + # tags = "" + # environment = "test" + print('测试目录:', suite_dirs) + print('测试文件:', file_names) + print('测试标签:', tags) + print('测试环境:', environment) + sub_procs = [] + for file_name in file_names: + if platform.system().upper() == 'WINDOWS': + cmd = f'python runner.py -d "{suite_dirs}" -s "{file_name}" -e "{environment}"' + if tags: + cmd += f' -t "{tags}"' + else: + cmd = f'python3 runner.py -d "{suite_dirs}" -s "{file_name}" -e "{environment}"' + if tags: + cmd += f' -t "{tags}"' + print(cmd) + sub_procs.append(subprocess.Popen(cmd, shell=True)) + for proc in sub_procs: + proc.wait()