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 OverflowThis post was mass deleted and anonymized with Redact
lock relieved tie boast hat fearless heavy act fear point
Debugger doesn't stop at breakpoints with pytest if pytest-cov is used
python - VSCode: Why isn't debugger stopping at breakpoints? - Stack Overflow
unit testing - Can I debug with python debugger when using py.test somehow? - Stack Overflow
python - Unable to debug in pycharm with pytest - Stack Overflow
Videos
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
},
]
}
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"}
}
]
}
it's real simple: put an assert 0 where you want to start debugging in your code and run your tests with:
py.test --pdb
done :)
Alternatively, if you are using pytest-2.0.1 or above, there also is the pytest.set_trace() helper which you can put anywhere in your test code. Here are the docs. It will take care to internally disable capturing before sending you to the pdb debugger command-line.
I found that I can run py.test with capture disabled, then use pdb.set_trace() as usual.
> py.test --capture=no
============================= test session starts ==============================
platform linux2 -- Python 2.5.2 -- pytest-1.3.3
test path 1: project/lib/test/test_facet.py
project/lib/test/test_facet.py ...> /home/jaraco/projects/project/lib/functions.py(158)do_something()
-> code_about_to_run('')
(Pdb)
For my situation, I found what the problem is:
If there is --cov in pytest.ini, then breakpoints in pycharm won't work, after deleting all --cov in pytest.ini, the breakpoints in pycharm can work.
Reason:
"The coverage module and pycharm's debugger use the same tracing api (sys.settrace) - they don't work together. " -- https://github.com/pytest-dev/pytest-cov/issues/131
References:
How to debug py.test in PyCharm when coverage is enabled
The root issue is debugging does not work if you have coverage enabled by default (usually on pytest.ini).
To disable just on pycharm, just add --no-cov on the Additional Arguments on the Run/Debug Configurations.
Update Templates -> Python tests -> pytest, so every new test gets this configuration.
After this, delete your current debug settings and redebug it.

Pycharm 2018.3.x (still works in 2020.x)