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 the launch.json file in the .vscode folder 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.json file disables the justMyCode setting 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 Overflow
🌐
Visual Studio Code
code.visualstudio.com › docs › python › testing
Python testing in Visual Studio Code
November 3, 2021 - To customize settings for debugging tests, you can specify test debug configs in either the launch.json or settings.json files in the .vscode folder from your workspace by adding the "purpose": ["debug-test"] to your config. 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.json file disables the justMyCode setting for debugging tests:
Top answer
1 of 2
23

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 the launch.json file in the .vscode folder 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.json file disables the justMyCode setting 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.

2 of 2
6

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"
}
Discussions

VS Code / Python / Debugging pytest Test with the Debugger - Stack Overflow
How can I get VS Code to put me into the debugger at the point of failure when running tests with pytest? Pytest catches all errors and asserts, and VS code invokes the debugger only on uncaught er... More on stackoverflow.com
🌐 stackoverflow.com
Unable to disable justMyCode in Test Debugging
The sample project consists of ... to use pytest, python 3.12.1: import logging logger = logging.getLogger() def test_test(): logger = logging.getLogger() The debugger doesn't step into any of these logging.getLogger() when run as test, and successfully does it if run directly. When the debugger skips a step-in, the notification appears: Frame skipped from debugging during step-in. Note: may have been skipped because of "justMyCode" option (default ... More on github.com
🌐 github.com
1
February 9, 2024
Python separate pytest config for running tests vs debugging
Unfortunately, as of now, there's no built-in way in VS Code to specify a different pytest configuration when debugging a single test. More on reddit.com
🌐 r/vscode
3
2
February 15, 2024
how to disable justMyCode in unittest debug
I search it , and i cannot find solution More on github.com
🌐 github.com
6
August 23, 2019
🌐
GitHub
github.com › microsoft › vscode-python › issues › 21249
JustMyCode doesn't work when debugging python tests through the GUI · Issue #21249 · microsoft/vscode-python
May 15, 2023 - Type: Bug Behaviour Expected vs. Actual I cannot disable "just my code" and debug tests through the GUI. Also, [object Object] notification keeps popping Steps to reproduce: When I setup the "Python: Debug Tests" configuration in my code...
Published   May 15, 2023
Author   NicolasM-Forsk
🌐
GitHub
github.com › microsoft › vscode-python-debugger › issues › 207
Unable to disable justMyCode in Test Debugging · Issue #207 · microsoft/vscode-python-debugger
February 9, 2024 - Try setting "justMyCode": false in the debug configuration (e.g., launch.json).
Author   roman-anna-money
🌐
Reddit
reddit.com › r/vscode › python separate pytest config for running tests vs debugging
r/vscode on Reddit: Python separate pytest config for running tests vs debugging
February 15, 2024 -

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",
          }
        }
🌐
GitHub
github.com › microsoft › vscode-python › issues › 7083
how to disable justMyCode in unittest debug · Issue #7083 · microsoft/vscode-python
August 23, 2019 - area-debugginginfo-neededIssue requires more information from posterIssue requires more information from poster
Author   chen19901225
🌐
Endjin
endjin.com › blog › 2024 › 09 › how-to-step-into-external-code-when-debugging-a-python-behave-test-in-vs-code
How to step into external code when debugging a Python Behave test in VS Code | endjin
September 26, 2024 - If you want to step into external code when debugging a Python behave test, you will find that the usual VS Code mechanisms for configuring debugging do not work. In this post I'll show you how you can enable this. TLDR; In settings.json add the following line: "behave-vsc.justMyCode": false.
Find elsewhere
🌐
ComfyUI
mslinn.com › blog › 2023 › 08 › 20 › pytest-intro.html
Pytest and Visual Studio Code
August 20, 2023 - Run and Debug configurations that invoke the pytest module work perfectly. Here is an example .vscode/launch.json that demonstrates this: ... { "version": "0.2.0", "configurations": [ { "name": "PyTest All", "type": "python", "request": "launch", "module": "pytest", "justMyCode": true }, { "args": ["--nf", "--lf"], "name": "PyTest New and Failing", "type": "python", "request": "launch", "module": "pytest", "justMyCode": true }, ] } 😁
🌐
Reddit
reddit.com › r/djangolearning › how to setup vscode to debug django app tests (pytest)?
r/djangolearning on Reddit: How to setup VScode to debug Django app tests (pytest)?
March 28, 2023 -

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

}

]

```

🌐
YouTube
youtube.com › 0xdf
Configuring VSCode to Debug PyTest - YouTube
While doing an Advent of Code challenge, I found myself really wanting to debug PyTest. This video shows how I set that up.VSCode Variables: https://code.vis...
Published   July 7, 2023
Views   5K
🌐
Visual Studio Code
code.visualstudio.com › docs › python › debugging
Python debugging in VS Code
November 3, 2021 - This article mainly addresses Python-specific debugging configurations, including the necessary steps for specific app types and remote debugging.
🌐
GitHub
github.com › microsoft › vscode-python › issues › 7347
"justMyCode" does not enable standard library debugging · Issue #7347 · microsoft/vscode-python
September 12, 2019 - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal", "subProcess": true, "justMyCode": false, } ] } Simple .venv created and pytest installed, attempting to debug this: import subprocess def test_run(): a = subprocess.call("pwd") print(a) After setting breakpoint call on the line including the subprocess call, I can use F11 to step into standard library.
Author   DazEdword
🌐
Visual Studio Marketplace
marketplace.visualstudio.com › items
Python Test Explorer for Visual Studio Code - Visual Studio Marketplace
February 3, 2024 - Extension for Visual Studio Code - Run your Python tests in the Sidebar of Visual Studio Code
🌐
TMS Outsource
tms-outsource.com › home › how to run pytest in vscode for testing
How to Run Pytest in VSCode for Testing - TMS Outsource
January 7, 2026 - Debug pytest tests by setting breakpoints in your test code, then right-clicking the test and selecting “Debug Test”. VSCode launches the debugger, pauses at breakpoints, and provides access to the Debug Console for inspecting variables ...
🌐
Darklab8
darklab8.github.io › blog › article_visual_debugger_in_vscode.html
Vscode debugger recipes for python and docker- blog
The justMyCode: false setting in launch.json allows navigation through third-party library code, even during visual debugging from unit tests. ... deactivate python3 -m venv .venv source .venv/bin/activate # at windows can be `venv\Scripts\activate` ...