Search code examples
pythonjsonvisual-studio-codevisual-studio-debugginglaunch

Visual Studio Code Python debugger does not trigger breakpoints in subfolder files


I am using Visual Code 1.55.2 on Ubuntu 20.04 LTS. I have a simple problem, i.e. I cannot trigger breakpoints if they are in a subfolder of my project's one. This is my launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Main",
            "type": "python",
            "request": "launch",
            "program": "Main.py",
            "console": "integratedTerminal",
            "cwd": "${fileDirname}"
        }
    ]
}

I added the cwd attribute and specified the program name and file to be run. So now, whenever I click on my debug configuration everything works fine, apart from the fact that some breakpoints are ignored. This is a facsimile of my working directory:

.
├── subfolder
│   ├── subfile1.py
│   └── subfile2.py
├── file1.py
├── file2.py
├── file3.py
├── file4.py
├── Main.py
└── .vscode
    └── settings.json

All the breakpoints in subfile1.py and subfile2.py are ignored.

I have tried to read the official documentation, but I could not understand it well enough.

Thanks for your help!

--- UPDATE ---

Sadly, I am not allowed to share my code, so I can olny describe the problem by words or via examples.

That said, I just finished testing some more this issue, and I discovered that subfolders are not a problem per se, but, regardless, the debugger skips a breakpointed line in my code that I am sure gets read The breakpointed line is correctly listed In the "Run and Debug" tab, "breakpoints" section, like the sample in the figure below (Notice that the "Python: Main" config file content is shown in the previous paragraph):

breakpoint correctly listed in my sample code

In fact, my problems with VS code started as soon as I decided to debug this project with it instead of relying on pyCharm, which had been working fine, without any issue. To provide some more conxtext, I can say that my project involves PyQt5, so it creates an interactive window on screen. The code portion I am testing should trigger after ask the program to open a file via a button on the GUI (which works fine), and then I actually pick a file from the OS-managed file explorer. Sadly, the breakpoint does not trigger. With pyCharm, everything works as expected: once I get to that specific line, the code stops. This does not happen with VS code, so either the debugger behaves differently or there are some settings that need to be tweaked. The only VS code "tweaking/settings variable" I know about is the launch.json.

Given these new insights, the problem seems more a sort of unresponsiveness from the IDE, because if I set a breakpoint at the first line of that specific file, the debugger actually stops there. So what I tried next was to leave both the breakpoints on (the one at the first line and the "not-triggering" one), and see what happens: the first breakpoint works, the second one is still ignored. I am using the anaconda "base" environment and its interpreter in both IDEs, if that matters.


Solution

  • Use the default debug configuration and try again:

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

    enter image description here

    More information about debug please view Debugging and Python debug configurations in Visual Studio Code.