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 Overflow
Discussions

Debugging tests is not stopping on breakpoint
Type: Bug Behaviour Expected vs. Actual Expected: setting a breakpoint on a test and then debugging the test should trigger the breakpoint to enable step-by-step execution of the test. Actual: the ... More on github.com
🌐 github.com
25
January 13, 2023
VS Code / Python / Debugging pytest Test with the Debugger - Stack Overflow
I guess this is a problem of pytest, which cannot be made to raise the error, so it remains uncaught, triggering the VSC debugger. 2020-08-31T11:51:09.77Z+00:00 ... @mgf Thank you for your feedback. At present, VSCode cannot automatically catch errors when debugging test scripts, unless we set breakpoints ... More on stackoverflow.com
🌐 stackoverflow.com
python - VSCode Test Debugger not stopping at breakpoints when using coverage - Stack Overflow
As the VSCode docs say · Note If you have the pytest-cov coverage module installed, VS Code doesn't stop at breakpoints while debugging because pytest-cov is using the same technique to access the source code being run. To prevent this behavior, include --no-cov in pytestArgs when debugging ... More on stackoverflow.com
🌐 stackoverflow.com
VS Code Debugger not working for python
I am experiencing debugging issue for my VS Code in WIN-10. It happened since weekend when I did OS restart . It was working fine before and I had launch.json configured too. Debugging was working fine. Any troubleshooting tips. It seems when I do… More on learn.microsoft.com
🌐 learn.microsoft.com
7
3
January 11, 2023
🌐
GitHub
github.com › microsoft › vscode-python › issues › 693
Debugger doesn't stop at breakpoints with pytest if ...
February 2, 2018 - area-debuggingarea-testingfeature-requestRequest for new features or functionalityRequest for new features or functionalityneeds PRReady to be worked onReady to be worked on ... VS Code version: 1.19.3 Python Extension version: 2018.1.0 Python Version: 3.6.2 OS and version: Windows 10 latest update ... This adds automatically a "--cov" to every "pytest" call, but prevents VSCode to stop at breakpoints.
Author   lmazuel
🌐
Visual Studio Code
code.visualstudio.com › docs › python › testing
Python testing in Visual Studio Code
November 3, 2021 - If you have the pytest-cov coverage ... to access the source code being run. To prevent this behavior, include --no-cov in pytestArgs when debugging tests, for example by adding "env": {"PYTEST_ADDOPTS": "--no-cov"} to your ...
🌐
GitHub
github.com › microsoft › debugpy › issues › 1175
Debugging tests is not stopping on breakpoint · Issue #1175 · microsoft/debugpy
January 13, 2023 - Actual: the test just runs through. The debugger panel appears at the top of the window but the debugger never stops execution of the code. Right-click on the green run button in the test file's gutter. Click "Add breakpoint".
Author   pcolmer
Find elsewhere
🌐
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",
          }
        }
🌐
Lightrun
lightrun.com › answers › microsoft-vscode-python-debugger-doesnt-stop-at-breakpoints-with-pytest-if-pytest-cov-is-used
Debug Daily - Real-World Developer Solutions & Troubleshooting
June 6, 2022 - Debug Daily provides real-world solutions to common developer problems. Find answers to GitHub Actions errors, React Native issues, Python bugs, and more. Sponsored by Lightrun.
🌐
Donjayamanne
donjayamanne.github.io › pythonVSCodeDocs › docs › troubleshooting_debugger
Debugger | Python in Visual Studio Code
Solution: Clear all expressions from the debugger Watch window and start debugging again.
🌐
GitHub
github.com › microsoft › debugpy › issues › 1289
Pytest debug breakpoints not hit using python 3.11 · Issue #1289 · microsoft/debugpy
May 11, 2023 - Type: Bug Behaviour Running a pytest in debug mode no longer stops at breakpoints when using Python 3.11 (works in Python3.10). Expected vs. Actual Pytest running in debug mode should stop on breakpoints. Instead it doesn't and the follo...
Published   May 11, 2023
Author   morybc
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-20186
debugging of py.test does not stop on breakpoints if ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
GitHub
github.com › microsoft › debugpy › issues › 1347
When debugging a pytest unittest in VSCode, the python debugger detaches after ~60s, and I can't find an overriding timeout setting · Issue #1347 · microsoft/debugpy
August 7, 2023 - When debugging a pytest unittest in VSCode, the python debugger detaches after ~60s, and I can't find an overriding timeout setting#1347 ... When debugging a pytest unittest using the inline right-click debug from a specific test, I can debug for as long as I want; i.e., the debugger stays connected and breaks on breakpoints, etc., without timing out, OR the extension allows me to set a timeout for as long as I want.
Author   haughki
🌐
Copdips
copdips.com › 2024 › 02 › debugging-in-python.html
Debugging in Python - A code to remember - Copdips.com
February 22, 2024 - This is because pytest-cov uses sys.settrace() to track code coverage, which is in conflict with breakpoints. There's no final solution for this issue, a workaround is to whether use coverage or whether use debug. In an IDE session (VSCode for e.g.), we can use make test to launch the test and generate coverage report with pytest --cov, and then use VScode's built-in debugger to set breakpoints and launch the tests in debug mode.
🌐
GitHub
github.com › microsoft › debugpy › issues › 544
Can't debug my pytest unittests from VS Code · Issue #544 · microsoft/debugpy
February 12, 2021 - ============================= test session starts ============================= platform win32 -- Python 3.7.9, pytest-6.2.0, py-1.10.0, pluggy-0.13.1 rootdir: c:\dev\ingest_oba, configfile: obabr\pytest.ini plugins: hypothesis-6.0.3, forked-1.3.0, profiling-1.7.0, timeout-1.4.2, xdist-2.2.0 collected 1 item obabr\tests\download_test.py . [100%] - generated xml file: C:\Users\ppppp\AppData\Local\Temp\tmp-15396J3k1TtjEH4i3.xml - ============================== 1 passed in 0.13s ============================== And nothing happens. :-( If from my activated workspace in a _ bash shell_ I run the following command: python -m debugpy --wait-for-client --listen 0.0.0.0:5678 ../../Scripts/pytest.exe download_test.py
Author   pauloneves
🌐
Visual Studio Code
code.visualstudio.com › docs › python › debugging
Python debugging in VS Code
November 3, 2021 - Local computer: switch to the Run and Debug view (⇧⌘D (Windows, Linux Ctrl+Shift+D)) in VS Code, select the Python Debugger: Attach configuration · Local computer: set a breakpoint in the code where you want to start debugging.
🌐
JetBrains
youtrack.jetbrains.com › issue › PY-20186 › debugging-of-pytest-does-not-stop-on-breakpoints-if-coverage-plugin-enabled
debugging of py.test does not stop on breakpoints if coverage ...
June 9, 2023 - {{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong