I'd try following the instructions from the VS Code Python docs' section on debugging tests, which states:
To customize settings for debugging tests, you can specify
"purpose": ["debug-test"]in thelaunch.jsonfile in the.vscodefolder from your workspace. This configuration will be used when you run Test: Debug All Tests, Test: Debug Tests in Current File and Test: Debug Test at Cursor commands.For example, the configuration below in the
launch.jsonfile disables thejustMyCodesetting for debugging tests:{ "name": "Python: Debug Tests", "type": "debugpy", "request": "launch", "program": "${file}", "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": false }If you have more than one configuration entry with
"purpose": ["debug-test"], the first definition will be used since we currently don't support multiple definitions for this request type.
Note: I've also seen older configs floating around that use "request": "test" instead of "purpose": ["debug-test"] (Ex. this), so you can try that if "purpose": ["debug-test"] doesn't work for you.
There also seems to be a "debugStdLib": true property you can use if you want to step into standard library things (source).
There's an open issue ticket where this is apparently not working for version 2023.8.0 of the Python extension (#21249), but it will be fixed in later versions. Also potentially related: Pytest restart debugger works only with code-workspace files #21365.
Answer from starball on Stack OverflowI'd try following the instructions from the VS Code Python docs' section on debugging tests, which states:
To customize settings for debugging tests, you can specify
"purpose": ["debug-test"]in thelaunch.jsonfile in the.vscodefolder from your workspace. This configuration will be used when you run Test: Debug All Tests, Test: Debug Tests in Current File and Test: Debug Test at Cursor commands.For example, the configuration below in the
launch.jsonfile disables thejustMyCodesetting for debugging tests:{ "name": "Python: Debug Tests", "type": "debugpy", "request": "launch", "program": "${file}", "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": false }If you have more than one configuration entry with
"purpose": ["debug-test"], the first definition will be used since we currently don't support multiple definitions for this request type.
Note: I've also seen older configs floating around that use "request": "test" instead of "purpose": ["debug-test"] (Ex. this), so you can try that if "purpose": ["debug-test"] doesn't work for you.
There also seems to be a "debugStdLib": true property you can use if you want to step into standard library things (source).
There's an open issue ticket where this is apparently not working for version 2023.8.0 of the Python extension (#21249), but it will be fixed in later versions. Also potentially related: Pytest restart debugger works only with code-workspace files #21365.
This is a limitation in current VSCode version: VSCode only uses launch.json file to configure pytest debugging options, it ignores the workspace launch section.
It is planned to be fixed soon: https://github.com/microsoft/vscode-python/issues/21249
As a workaround, we can duplicate the workspace launch section in a .vscode/launch.json file, ex:
{
"configurations": [
{
"name": "Python: Debug Tests",
"type": "python",
"request": "launch",
"program": "${file}",
"purpose": ["debug-test"],
"console": "integratedTerminal",
"justMyCode": false,
"presentation": {
"hidden": true, // keep original launch order in 'run and debug' tab
}
},
],
"version": "0.2.0"
}
Unable to disable justMyCode in Test Debugging
VS Code / Python / Debugging pytest Test with the Debugger - Stack Overflow
Python separate pytest config for running tests vs debugging
how to disable justMyCode in unittest debug
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.
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 need to stop debugger on one breakpoint in tests but i don't know how to do it.
How "configurations" in launch.json file should looks like? I trying with something like that but its doesnt work:
```
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django:web_cloud tests",
"python": "/home/szymon/app_project/venv/web_cloud/bin/python3",
"type": "python",
"request": "launch",
"program": "/home/szymon/app_project/app/web_cloud/manage.py",
"args": [
"pytest"
],
"console": "internalConsole",
"django": true,
"justMyCode": true
}
]
```
Just adding "justMyCode": false to launch.json doesn't work. You need to add a separate config in launch.json like below. FYI each {} represents a config.
"configurations": [
{
.... # existing config
},
{
"name": "Debug Unit Test",
"type": "python",
"request": "test",
"justMyCode": false,
}
]
As pointed out in here
For this you need to change the launch.json file. Inside the launch.json file you have to set "justMyCode" to false.
As described here. (I was pointed to that link through this post on the Visual Studio Code site.)