在 python 中,VSCode 调试器不会单步执行外部代码。无法弄清楚如何编辑 launch.json 中的“justMyCode”

Clo*_*oud 8 python visual-studio-code

我一直在参考https://code.visualstudio.com/docs/python/debugging#_justmycode 以及 如何在 VSCode 调试器中禁用“仅我的代码”设置?

尽管进行了多次尝试,仍然无法弄清楚在 launch.json 中将 "justMyCode": false 放在哪里。在我尝试添加它的每个地方,编辑器都会说“不允许使用 Property justMyCode ”

下面是我的 launch.json 的副本。有人可以告诉我我应该做什么吗?

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",

    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "justMyCode": false
        },
        {
            "name": "Python: Remote Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost",
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        },
        {
            "name": "Python: Module",
            "type": "python",
            "request": "launch",
            "module": "enter-your-module-name-here",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        },
        {
            "name": "Debug Unit Test",
            "type": "python",
            "request": "attach",
            "justMyCode": false
        }
    ]
}

Run Code Online (Sandbox Code Playgroud)

小智 7

Try setting "justMyCode": false正如 VS Code 调试器中的消息所示,这还不够。如果您想单步执行外部代码,您还需要更改"request": "launch"为。"request": "test"这是我在 Github 上找到答案的问题

  • 这对我来说也不起作用,它说我必须使用“Python:调试单元测试”。但我并不是想调试测试。我正在尝试一个常规的 python 文件。不确定OP正在尝试调试什么。编辑:我可以通过使用 "request:: "launch" 并将 "justMyCode": false 放入我的 launch.json 而不是全局 vscode 设置中来使其工作。 (2认同)

小智 5

你也需要放"purpose": ["debug-test"]

喜欢

"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "justMyCode": false,
        "purpose": ["debug-test"]
    }
],
Run Code Online (Sandbox Code Playgroud)