Visual Studio Code(VS代码)运行测试按钮工作正常,但调试测试没有

发布于 2025-02-09 12:10:26 字数 1674 浏览 0 评论 0原文

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,
    }
}

我通过此链接: 尝试了以下建议,没有任何运气:

  1. 将Python扩展降级到V2020.2.64397
  2. 将这些行包括在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:

  1. Downgrade the Python extention to v2020.2.64397
  2. Include these lines into launch.json:
{
     "name": "Python: Test debug config",
     "type": "python",
     "request": "test",
     "console": "integratedTerminal",
     "logToFile": true
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2025-02-16 12:10:26

您可以通过添加以下代码启动来指定Python解释器。

"python": "your python path"#for example "/AppData/Local/Programs/Python/Python310/python.exe"

You can specify the python interpreter by adding the following code to launch.json:

"python": "your python path"#for example "/AppData/Local/Programs/Python/Python310/python.exe"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文