Python多进程执行测试

# -*- coding:utf-8 -*-
import concurrent.futures
import logging
import os
import subprocess

import pytest

projectPath = os.path.dirname(os.path.abspath(__file__))
testcase_path = projectPath + '\\po_pattern\\testcase'
report_path = "--alluredir=multi_run/my_allure_results"

print('testcase_path:' + testcase_path)
# testcase = ["-s", "-v","--ff","-m sit_uat and not sit", report_path]
testcase = ["-s", "-v", "--env=sit", report_path]


# 创建测试函数
def run_test_class(test_module_name):
    working_directory = projectPath
    print('working_directory:' + working_directory)
    test_module_name = testcase_path + '\\' + test_module_name
    print("test_module_name=" + test_module_name)
    subprocess.run(['pytest', test_module_name, report_path])

    # subprocess.run(["pytest",test_module_name])

    # pytest.main([f"-k",test_module])




test_modules2 = ["data_retrieval_test.py", "data_retrieval_2test.py"]
if __name__ == '__main__':
    print(test_modules2)
    # 更改当前工作目录
    os.chdir(projectPath)
    with concurrent.futures.ThreadPoolExecutor() as executor:
        executor.map(run_test_class, test_modules2)

你可能感兴趣的:(python)