import time import pytest from lib.asr_models.base_model import ModelName from test_data import DataName def pytest_addoption(parser): # 注册命令行参数 parser.addoption( "--model", action="store", required=True, nargs="+", choices=["whisper", "whisper_finetuned", "funasr_nano", "funasr_mlt_nano","funasr_quant", "all"], help="Models to run" ) parser.addoption( "--dataset", action="store", required=True, nargs="+", choices=["wenet_net", "wenet_meeting", "librispeech_clean", "librispeech_other", "aishell2", "recording"], help=f"Datasets to use" ) def pytest_generate_tests(metafunc): # metafunc 可以获取到测试函数的信息 # 动态参数化 'model' if "model" in metafunc.fixturenames: model_list = metafunc.config.getoption("model") if "all" in model_list: model_list = [m.value for m in ModelName] metafunc.parametrize("model", model_list) # 动态参数化 'dataset' if "dataset" in metafunc.fixturenames: dataset_list = metafunc.config.getoption("dataset") metafunc.parametrize("dataset", dataset_list) @pytest.fixture(scope="module") def summary(request): # 在所有 case 运行完后打印总的结果 summary = [] yield summary print("\n\n") print("*"*50) [print(s) for s in summary] print("*" * 50) @pytest.fixture(scope="function", autouse=True) def print_log(request): model_name = request.node.callspec.params.get("model") dataset_name = request.node.callspec.params.get("dataset") print("\n", "#"*30,model_name, "-", dataset_name, "start", "#"*30, "\n") yield print("\n", "#" * 30, model_name, "-", dataset_name, "end", "#" * 30, "\n") time.sleep(30)