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

问题描述

Pytest 测试发现失败。用户界面指出:

Test discovery error, please check the configuration settings for the tests

输出窗口状态:

Test Discovery failed: 
Error: Traceback (most recent call last):
  File "C:\Users\mikep\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\testing_tools\run_adapter.py", line 16, in <module>
    main(tool, cmd, subargs, toolargs)
  File "C:\Users\mikep\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\testing_tools\adapter\__main__.py", line 90, in main
    parents, result = run(toolargs, **subargs)
  File "C:\Users\mikep\.vscode\extensions\ms-python.python-2019.4.11987\pythonFiles\testing_tools\adapter\pytest.py", line 43, in discover
    raise Exception('pytest discovery failed (exit code {})'.format(ec))
Exception: pytest discovery failed (exit code 3)

这是我的设置:

{
    "python.pythonPath": ".venv\\Scripts\\python.exe",
    "python.testing.pyTestArgs": [
        "tests"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pyTestEnabled": true
}

我可以从命令行成功运行 pytest FWIW。

标签: pythonvisual-studio-codepytestvscode-settings

解决方案


在创建了一个有导入错误的测试后,我花了很长时间试图破译这个无益的错误。在进行任何更深入的故障排除之前,验证您的测试套件是否可以实际执行。

pytest --collect-only是你的朋友。


推荐阅读