英文:
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?
答案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())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。




评论