1

When I run python in 1.84.2 vscode, I found that breakpoints did not work. It didn't stop where I interrupted, but stopped where thre was not breakpoint. This problem makes me very anxisous. I can't find a solution to the problem, and if I can't solve it, I would give up vscode, but I don't want to do this. Please help me.

The problem is as shown in: enter image description here

launch.json file

"version": "0.2.0",
"configurations": [
    {
        "name": "Python: Current File",
        "type": "python",
        "request": "launch",
        "program": "${file}",
        "console": "integratedTerminal",
        "justMyCode": true,
        
    }

I don't know where the porblem is, I didn't have any problem before, but this problem occurred when I used it two months later. Please help me, thank you.

7
  • tf belongs to the package you imported, and only your code will be debugged according to your launch.json, so it will skip this breakpoint. You have to change "justMyCode": true, to false. Commented Nov 13, 2023 at 7:17
  • I tried it but the problem is still not solved. In addtion, I also made several attempts, such as installing an older version of vscode, add ""purpose":["debug-in-terminal"]" in setting file and restarting vscode, but it still didn't work. And I found some problem: when running other files, the problem of invalid breakpoints will not occur, even if justMyCode set to true, and sometimes breakpoints work, but it is invalid when running again. What is the reason for this? Commented Nov 13, 2023 at 8:10
  • Is there any error report when debugging? I see that your python doesn't provide intellisense correctly, a possible conjecture that you didn't choose the python environment correctly. Commented Nov 13, 2023 at 8:28
  • 1
    1) Please copy and paste the output of the Help: About command (run in the command palette) into your question post. 2) Please also add the version of your Python extension. Commented Nov 13, 2023 at 8:47
  • There is no error, it just does not stop where there is a breakpoint, but stops where there is no breakpoint. How to choose the python environment correctly? You mean installing python plugins in extensions? Commented Nov 13, 2023 at 9:49

4 Answers 4

5

I had the same problem and it turn out that it was due to having installed pytest-cov.

The solution is to add the argument --no-cov to python.testing.pytestArgs, as it is pointed in the documentation

Credits to this asnwer for getting me in the right track.

Sign up to request clarification or add additional context in comments.

Comments

2

You will need to change your setting "justMyCode" to false for breakpoints to work in vscode.

More can be read Here

1 Comment

I tried it but the problem is still not solved. In addtion, I also made several attempts, such as installing an older version of vscode, add ""purpose":["debug-in-terminal"]" in setting file and restarting vscode, but it still didn't work. And I found some problem: when running other files, the problem of invalid breakpoints will not occur, even if justMyCode set to true, and sometimes breakpoints work, but it is invalid when running again. What is the reason for this?
0

Use the left side menu to debug; worked for me enter image description here

Comments

0

I added a remote debugger launcher in configurations:

{
    "name": "Python Debugger: Remote",
    "type": "debugpy",
    "request": "attach",
    "connect": {
        "host": "localhost",
        "port": 5678
    },
    // It needs to know all the source dirs
    "pathMappings": [
        {
            "localRoot": "${workspaceFolder}/src",
            "remoteRoot": "src" // ./src doesn't work
        },
        {
            "localRoot": "${workspaceFolder}/tests",
            "remoteRoot": "tests"
        }
    ],
    "justMyCode": false // Consider 'remote' code too
}

It started to work when I added both the source paths to pathMappings. I guess other debugging modes support this.

I have a TOML/Poetry based project, and I'm debugging it from the launch of pytest, the debugged process starts like this:

$ python -m debugpy --listen 5678 --wait-for-client -m pytest

This waits for the Debugger (ie, VSCode) to connect as a client, then it start running and stops upon a breakpoint or exception, and you can see the usual UI in VSC.

This works when launched under the proper environment (eval $(poetry env activate), use the 'activate' command for your virtual environment manager) and after having installed debugpy in such environment (poetry add --group dev debugpy).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.