Setting "justMyCode": false makes it stop at breakpoint:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"stopOnEntry": true,
"justMyCode": false
},
]
}
Answer from Ashish on Stack OverflowSetting "justMyCode": false makes it stop at breakpoint:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Debug Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"stopOnEntry": true,
"justMyCode": false
},
]
}
If you're using a pytest-cov module you might also wanna have a look at pytest configuration settings note:
Note If you have the
pytest-covcoverage module installed, VS Code doesn't stop at breakpoints while debugging becausepytest-covis using the same technique to access the source code being run. To prevent this behavior, include--no-covinpytestArgswhen debugging tests, for example by adding"env": {"PYTEST_ADDOPTS": "--no-cov"}to your debug configuration.
See an example configuration file (launch.json) below:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Tests",
"type": "python",
"request": "test",
"console": "integratedTerminal",
"justMyCode": false,
"env": {"PYTEST_ADDOPTS": "--no-cov"}
}
]
}
This post was mass deleted and anonymized with Redact
lock relieved tie boast hat fearless heavy act fear point
Debugging tests is not stopping on breakpoint
VS Code / Python / Debugging pytest Test with the Debugger - Stack Overflow
python - VSCode Test Debugger not stopping at breakpoints when using coverage - Stack Overflow
VS Code Debugger not working for python
Videos
If you want to enter debugging when running pytest in VSCode and stay at a line of code, you could click 'Debug Test' at the top of the method after selecting the pytest test, as shown in the screenshot:

In addition, "python.testing.pytestArgs": [], in .vscode\settings.json is the folder path of the tested file, for example, my test file is in Test_cc under the a folder.
> "python.testing.pytestArgs": [
> "a/Test_cc"
> ],
If this is not what you want, please let me know and describe the details of your needs.
Reference: Debug tests.
Update:
Usually, when we debug the test in VSCode, without setting a breakpoint for it, it will only display the test result. (success or failure). It will only display relevant test information in the console OUTPUT.
When I use the extension 'Python Test Explorer for Visual Studio code', it will display the debugging test information on the console, prompting the issue.

This Answer actually solves the problem. I wish there would be a more straight-forward way, either from Visual Studio Code or a simple raise flag from pytest.
I went trough something similar recently and found this page when searching the error.
Unlike you, I didn't want to run coverage tests in VS Code, so I could simply disable it in settings.json passing the --no-cov argument:
"python.testing.pytestArgs": [
"--import-mode=importlib",
"--no-cov"
]
This solved the debugger not stopping at breakpoints problem for me.
You could try to use the following codes in your launch.json:
{
"name": "Python: Debug Tests",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"justMyCode": true,
"env": {
"ON_HEROKU": "0",
"PYTEST_ADDOPTS": "-c pytest-debug.ini",
"ECHO_SQL_QUERIES": "1"
},
}
pytest-debug.ini is a separate configuration file for debugging. This file should be similar to your pytest.ini file, but without the addopts line:
[pytest]
env =
TESTING=true
ENV=local
This way, when you're debugging your tests, pytest will use the pytest-debug.ini configuration file.
The Python extension is broken - just seems to have updated at the same time as VS Code.
Go back to extension version v2021.12.1559732655 by clicking on the extensions control and selecting "Install another version...". Note that you will have to disable "Extensions: Auto Update", which might be a good thing. I also set "Update: Mode" to "none" for good measure.
So this bug is back with Python Extension version v2022.10.1 running on Ubuntu 18.04 with python 3.6.9.
This is a serious bug that keeps happening.
I had to roll back to extension version v2021.12.1559732655 to debug.
Hello, I am hoping someone here has an idea on how to do this.
I have a pytest.ini that looks like this
[pytest]
addopts = -n auto --dist worksteal --cov-report xml:coverage.xml
This works great when running the tests so they run quickly and I get test coverage. However, when I try to debug a single by right clicking on the green arrow for the test and selecting debug it won't hit any breakpoints in the test. If I remove the pytest.ini config then it will hit the breakpoints.
Does anyone know of a way to have a separate config when running a single test.
Thanks
UPDATE: I figured out a way to make this work. It turns out using type debugpy will not work and doesn't even read the environment variable. However, if I set the type to python it works just fine. It looks like this is a feature that debugpy needs to support.
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"env": {
"PYTEST_ADDOPTS": "-c pytest_alt.ini",
}
}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.
You will need to change your setting "justMyCode" to false for breakpoints to work in vscode.
More can be read Here
