Visual Studio Code(VS代码)运行测试按钮工作正常,但调试测试没有
vs Code
在运行测试
按钮时正常工作(是否通过测试选项卡(左侧)或右键单击“测试”),但调试测试
按钮记录此错误:
.
.
.
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/xxx/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/testlauncher.py", line 44, in <module>
run(cwd, testRunner, args)
File "/Users/xxx/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/testlauncher.py", line 34, in run
import pytest
ModuleNotFoundError: No module named 'pytest'
settings.json
{
"python.testing.pytestArgs": [
"packages/xxxxxx/tests/unit/xxxxxx/xxxxx",
"-s",
],
"python.testing.pytestPath": "runtimes/.venv/xxxxxx/bin/pytest",
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.enabled": false,
"files.exclude": {
"**/*.pyc": true,
}
}
我通过此链接: 尝试了以下建议,没有任何运气:
- 将Python扩展降级到V2020.2.64397
- 将这些行包括在
aunplion.json.json
:
{
"name": "Python: Test debug config",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"logToFile": true
}
VS Code
works just fine when Run Test
button (does not matter if via testing tab (left side) or by right click close to the test) but Debug Test
button logs this error:
.
.
.
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/Users/xxx/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/testlauncher.py", line 44, in <module>
run(cwd, testRunner, args)
File "/Users/xxx/.vscode/extensions/ms-python.python-2022.4.1/pythonFiles/testlauncher.py", line 34, in run
import pytest
ModuleNotFoundError: No module named 'pytest'
settings.json
{
"python.testing.pytestArgs": [
"packages/xxxxxx/tests/unit/xxxxxx/xxxxx",
"-s",
],
"python.testing.pytestPath": "runtimes/.venv/xxxxxx/bin/pytest",
"python.testing.pytestEnabled": true,
"python.linting.pylintEnabled": false,
"python.linting.enabled": false,
"files.exclude": {
"**/*.pyc": true,
}
}
I went through this link:
Tried the below suggestions, without any luck:
- Downgrade the Python extention to v2020.2.64397
- Include these lines into
launch.json
:
{
"name": "Python: Test debug config",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"logToFile": true
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过添加以下代码启动来指定Python解释器。
You can specify the python interpreter by adding the following code to launch.json: