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.

Answer from Jill Cheng on Stack Overflow
Discussions

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
Can't debug my pytest unittests from VS Code
VS Code does not stops at my breakpoints, nor from running from test tabs , nor trying to stepping into a file, nor running python -m debugpy and trying to attach to it. I want to be able to click in the highlighted icon below of one of my pytest unit tests: More on github.com
🌐 github.com
7
February 12, 2021
When debugging a pytest unittest in VSCode, the python debugger detaches after ~60s, and I can't find an overriding timeout setting
Type: Bug Behaviour Expected vs. Actual Expected 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 stay... More on github.com
🌐 github.com
3
August 7, 2023
Can't debug tests in python
pytest ran `main.py` not `test_main.py`. On which current buffer did you run the command? I advise you to use https://github.com/nvim-neotest/neotest-python which will make dap + pytest integration much easier. More on reddit.com
🌐 r/neovim
6
1
November 16, 2023
🌐
Pyleecan
pyleecan.org › tests_tutorials › how.to.debug.with.pytest.html
Debugging with pytest — PYthon Library for Electrical Engineering Computational ANalysis
April 28, 2023 - pytest.set_trace() Here is an example in pyleecan\Tests\Methods\Slot\test_HoleM50_meth.py: def test_build_geometry_two_hole_with_magnet(self): """check that curve_list is correct (one hole)""" test_obj = LamHole(is_internal=True, is_stator=False, Rext=0.075) test_obj.hole = list() test_obj.hole.append( HoleM50( Zh=8, W0=50e-3, W1=2e-3, W2=1e-3, W3=1e-3, W4=20.6e-3, H0=17.3e-3, H1=1.25e-3, H2=0.5e-3, H3=6.8e-3, H4=1e-3, magnet_0=MagnetType10(Wmag=0.01, Hmag=0.02), ) ) a = 5 pytest.set_trace() result = test_obj.hole[0].build_geometry() assert len(result) == 6 for surf in result: assert type(surf) is SurfLine assert result[0].label[:5] == "Hole_" assert result[0].label[-9:] == "_R0_T0_S0" assert len(result[0].line_list) == 7 ·
🌐
SeleniumBase
seleniumbase.com › home › the ultimate pytest debugging guide
The ultimate pytest debugging guide - SeleniumBase
June 25, 2022 - The pytest unit-testing framework for Python comes with some powerful debugging abilities via the interactive Python debugger (“Debug Mode”), which utilizes the following two libraries: the included pdb library, and the improved (but optional) ipdb library.
🌐
Qxf2 BLOG
qxf2.com › home › debugging in python using pytest.set_trace()
Debugging in Python using pytest.set_trace() - Qxf2 BLOG
October 30, 2024 - The main advantage is you can monitor the state of variables, stop and resume the flow of execution, set breakpoints etc. This post lets you understand how to use the Python debugger features with pytest options and inserting set_trace() statements inside your code. This post uses our test_example_form.py as example to illustrate different pdb tracing features.
🌐
Towards Data Science
towardsdatascience.com › home › latest › pytest tutorial: an introduction to unit testing
Pytest Tutorial: An Introduction To Unit Testing | Towards Data Science
July 23, 2025 - Let’s go through a very simple example. First, we will create a new directory pytest-example/ containing two files: calculations.py and test_calculations.py.
🌐
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",
          }
        }
Find elsewhere
🌐
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
🌐
pytest
docs.pytest.org › en › 6.2.x › usage.html
Usage and Invocations — pytest documentation
# content of test_example.py import pytest @pytest.fixture def error_fixture(): assert 0 def test_ok(): print("ok") def test_fail(): assert 0 def test_error(error_fixture): pass def test_skip(): pytest.skip("skipping this test") def test_xfail(): pytest.xfail("xfailing this test") @pytest.mark.xfail(reason="always xfail") def test_xpass(): pass
🌐
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 - OUTPUT - Python 2023-08-07 11:59:40.858 [info] Running PYTEST execution for the following test ids: tests/operations/test_sequence_to_helm.py::test_set_breakpoint_and_watch_test_timeout 2023-08-07 11:59:40.858 [info] Server listening on port 37781 2023-08-07 11:59:40.858 [info] Running DEBUG pytest with arguments: --rootdir /home/hawk/projects/cdd_peptide_reg --capture no 2023-08-07 11:59:40.860 [info] Using launch configuration in launch.json file. 2023-08-07 11:59:41.352 [info] DAP Server launched with command: /home/hawk/projects/cdd_peptide_reg/conenv/bin/python /home/hawk/.vscode-server/extensions/ms-python.python-2023.14.0/pythonFiles/lib/python/debugpy/adapter 2023-08-07 12:00:44.798 [info] Test server connected to a client.
Author   haughki
🌐
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 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 tests, for example by adding "env": {"PYTEST_ADDOPTS": "--no-cov"} to your debug configuration.
🌐
Reddit
reddit.com › r/neovim › can't debug tests in python
r/neovim on Reddit: Can't debug tests in python
November 16, 2023 -

I use nvim-dap with nvim-dap-python and nvim-dap-ui and I can't for the life of me make the debugger work with pytest.

.
├── pyrightconfig.json
├── pytest.ini
├── src
│   └── main
│       ├── __init__.py
│       ├── input.in
│       ├── main.py
│       └── tests
│           ├── __init__.py
│           └── test_main.py
└── venv

No custom configs except for keybindings. Using pytest in the terminal works normally as intended, but using nvim-dap-python's :lua require('dap-python').test_method() results to this:

============================= test session starts ==============================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/user/path/to/my/project/
configfile: pytest.ini
collected 0 items                                     
                         

============================ no tests ran in 0.01s =============================
ERROR: not found: /home/user/path/to/my/project/src/main/main.py::reverse_matrix_column (no name '/home/user/path/to/my/project/src/main/main.py::reverse_matrix_column' in any of [<Module main.py>])


[Process exited 4]

What am I doing wrong? Please help!

🌐
GitHub
github.com › microsoft › debugpy
GitHub - microsoft/debugpy: An implementation of the Debug Adapter Protocol for Python · GitHub
At the beginning of your script, import debugpy, and call debugpy.listen() to start the debug adapter, passing a (host, port) tuple as the first argument.
Starred by 2.4K users
Forked by 192 users
Languages   Python 92.8% | Cython 2.9% | Shell 1.8% | C++ 1.5% | Roff 0.8% | Perl 0.1%
🌐
Capital One
capitalone.com › tech › software-engineering › how-to-use-python-debugger-pdb
How to use pdb with pytest: Debugging unit tests in Python
December 1, 2021 - In this article, we demonstrate how to use pdb with pytest. First, here's a short introduction to debuggers plus how they compare with other tools like Jupyter. Next we provide a working example of a unit test that mocks a database connection.
🌐
JetBrains
jetbrains.com › help › pycharm › run-debug-configuration-py-test.html
Pytest | PyCharm Documentation
March 10, 2026 - Use this dialog to create a run/debug configuration for pytests.
🌐
pytest
docs.pytest.org › en › stable › how-to › failures.html
How to handle test failures - pytest documentation
Note that on any failure the exception information is stored on sys.last_value, sys.last_type and sys.last_traceback. In interactive use, this allows one to drop into postmortem debugging with any debug tool. One can also manually access the exception information, for example:
🌐
Darklab8
darklab8.github.io › blog › article_visual_debugger_in_vscode.html
Vscode debugger recipes for python and docker- blog
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Django", "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/manage.py", "args": ["runserver", "0.0.0.0:8000"], "django": true, "justMyCode": false }, { "name": "Python: Debug Tests", // KO with GUI (tests tab) "type": "debugpy", "request": "launch", "program": "${file}", "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": false }, { "name": "Debug specific tests", // OK with F5 "type": "debugpy", "module": "pytest",
🌐
PyPI
pypi.org › project › debugpy
debugpy · PyPI
An implementation of the Debug Adapter Protocol for Python
      » pip install debugpy
    
Published   Jan 29, 2026
Version   1.8.20
🌐
Noveogroup
blog.noveogroup.com › 2025 › 05 › vscode-debugger-recipes-python-and-docker
VSCode debugger recipes for Python and Docker - Blog - Noveo
May 7, 2025 - { "version": "0.2.0", "configurations": [ { "name": "Python: Fastapi", "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/app.py", "justMyCode": false }, { "name": "Python: Debug Tests", // KO with GUI (tests tab) "type": "debugpy", "request": "launch", "program": "${file}", "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": false }, { "name": "Debug specific tests", // OK with F5 "type": "debugpy", "module": "pytest", "request": "launch", "purpose": ["debug-test"], "console": "integratedTerminal", "justMyCode": false, "args": ["test_sample.py::test_answer"] }, { "name": "Python: Current File", // OK with F5 "type": "debugpy", "request": "launch", "program": "${file}", "console": "internalConsole", "justMyCode": false } ] } With written small code examples in app_test.py, we have no trouble launching visual debug for unit tests of fastapi ·
🌐
GitHub
github.com › microsoft › debugpy › issues › 1873
Pytest: stop on any failure in tests · Issue #1873 · microsoft/debugpy
March 18, 2025 - When I’m debugging a test with VSCode, I’m expecting the debugger to automatically add a breakpoint at the line where the test is failing. This is the behavior of pytest with the option --pdb, so I think it’s reasonable to expect the sam...
Author   k4nar