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。
似乎是最新版本的VS-Code-Python扩展中的一个bug。我遇到了同样的问题,然后我将Python扩展降级为2019.3.6558,然后它再次工作。因此,我们应该转到VS代码扩展列表,选择Python扩展并从该扩展的设置中“安装另一个版本…”。
我希望这对你也有用。
我用“pip install--upgrade pytest”将pytest升级到最新版本:4.4.1,解决了这个问题。我显然在运行一个旧版本3.4.2
这不是一个完整的答案,因为我不知道为什么会发生这种情况,可能与您的问题无关,这取决于您的测试结构。
我通过将
__init__.py
文件放在tests文件夹中解决了这个问题例如:
这在几天前还没有实现,但是python扩展最近更新了。我不确定这是否是计划中的行为,也不确定这是否是发现的副作用
https://github.com/Microsoft/vscode-python/blob/master/CHANGELOG.md
Use Python code for discovery of tests when using pytest. (#4795)
相关问题 更多 >
编程相关推荐