首页 > 解决方案 > VSCode pytest 测试发现失败?

问题描述

出于某种原因,VSCode 没有获取我的“test_*”文件?

这是代码:

import pytest
import requests
import responses

@responses.activate
def test_simple(api_key: str, url: str):
    """Test"""
    responses.add(responses.GET, url=url+api_key,
                  json={"error": "not found"}, status=404)

    resp = requests.get(url+api_key)

    assert resp.json() == {"error": "not found"}

我试过使用 CTRL+SHIFT+P 和配置测试,但这也失败了,它说:Test discovery failedTest discovery error, please check the configuration settings for the tests.

在我的设置中,唯一与 pytest 相关的是:"python.testing.pytestEnabled": true.

这里发生了什么?我的文件以“test”开头,我在该文件中的函数也是如此吗?

标签: python-3.xvisual-studio-codepytest

解决方案


推荐阅读