如何避免在pytest中出现”fixtures not found”错误?

huangapple go评论168阅读模式
英文:

How do I avoid the fixtures not found error in pytest?

问题

我正在尝试在pytest中进行工作流测试。

def test_workflow():
    with open("./configs.json", 'r') as f:
        CONFIGS = json.load(f)
    owner_id = CONFIGS['ownerId']
    project_name = CONFIGS['projectConfigs']['projectName']
    project_configs = CONFIGS['projectConfigs']
    project_configs['ownerId'] = owner_id

    projectId = test_project_creation(
        owner_id=owner_id,
        project_configs=project_configs,
        application_configs=CONFIGS['applicationConfigs'][CONFIGS['applicationName']],
    )

    input_video, output_ip, output_port, output_hls_link, input_hls_link = test_create_streams(
        input_stream_config=CONFIGS['inputStreamConfigs']
    )

test_workflow()方法中调用了各种步骤。当我在pytest中运行时,所有方法都正常运行,但我收到一个错误,其中提到“未找到fixtures”。是否有方法可以解决或抑制此错误?

英文:

I'm trying to conduct a workflow test in pytest.

def test_workflow():
    with open("./configs.json",'r') as f:
        CONFIGS = json.load(f)
    owner_id = CONFIGS['ownerId']
    project_name = CONFIGS['projectConfigs']['projectName']
    project_configs = CONFIGS['projectConfigs']
    project_configs['ownerId']  = owner_id


    projectId = test_project_creation(
        owner_id= owner_id,
        project_configs = project_configs,
        application_configs = CONFIGS['applicationConfigs'][CONFIGS['applicationName']],
    ) 

    input_video, output_ip, output_port, output_hls_link, input_hls_link = test_create_streams(
        input_stream_config=CONFIGS['inputStreamConfigs']
    )

Where I have a test_workflow() method that calls the various steps inside. Now the output of one testing step is being passed to others. When I run this in pytest, all the methods run properly but I get an error stating that fixtures not found. Is there a way to get around this or suppress it?

如何避免在pytest中出现”fixtures not found”错误?
如何避免在pytest中出现”fixtures not found”错误?

答案1

得分: 1

似乎 pytest 认为 test_project_creation 是一个单独的测试,需要命名为 owner_id 和其他的 fixture。尝试将 test_project_creation 和以 test_ 开头的其他函数重命名为不以 test_ 开头的名称(比如 create_project())。

英文:

It seems that pytest thinks that test_project_creation is a separate test which requires fixtures named owner_id and the others. Try to rename test_project_creation and other functions starting with test_ (except test_workflow) to something which doesn't starts with test_ (like create_project())

huangapple
  • 本文由 发表于 2023年6月22日 01:50:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525943.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定