File size: 1,837 Bytes
db0d138
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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)