Closed jeanlucthumm closed 1 year ago
The debugger works when I'm inside a non-test, main()
function, set a breakpoint, and do lua require'dap'.continue()
, so maybe there's something wrong with pytest setups specifically?
I'm having a similar issue. Configured nvim-dap-python
with examples from the docs
local mason_path = vim.fn.glob(vim.fn.stdpath "data" .. "/mason/")
require("dap-python").setup(mason_path .. "packages/debugpy/venv/bin/python")
require("dap-python").test_runner = "pytest"
-- mappings
lvim.builtin.which_key.mappings["dm"] = { "<cmd>lua require('dap-python').test_method()<cr>", "Test Method" }
lvim.builtin.which_key.mappings["df"] = { "<cmd>lua require('dap-python').test_class()<cr>", "Test Class" }
When invoking the test_method
-action in a pytest-unittest file, the debugger starts as expected, but does not stop at breakpoints. Same as for the others, the debugger and breakpoints work fine when used in "normal" python modules.
A minimal example with reproduction steps would be good.
Using a simple:
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
And running :lua require('dap-python').test_method()
with the cursor in test_answer
, test_runner
set to pytest
, and a breakpoint in the inc
body works fine for me.
Sorry for the late reply, I didn't find time to test it earlier.
I found out what broke it for me. I'm using a poetry environment in which all dev-tools are configured via the pyproject.toml
. PyTest is also configured in there:
[tool.pytest.ini_options]
addopts = "--cov" # <-- no stopping at breakpoints with --cov
testpaths = ["tests"]
When the --cov
is added nvim-dap-python does not stop at breakpoints, when I remove it it works fine.
Looks like this is a pytest-cov / debugpy limitation. See https://github.com/microsoft/debugpy/issues/863#issuecomment-1059040881
I set a breakpoint in my test file and it seems to pop up in the DAP logs:
But when I launch via the
test_method()
function, the program runs but never breaks.I looked at #17 and tried to change my python version. At first I was using
/usr/bin/python
(Python 3.10.8
) since my global install haddebugpy
. Then I created custom virtual env withPython 3.9.2
but the problem persists.My setup for the plugin: