Nvim-dap, Pytest, Debugpy and Docker
See original GitHub issueFirstly, this isn’t an issue with the plugin at all, more of a general question on being able to use vim-ultest
to debug remotely into a Docker container.
With my current config (for reference rather than to understand), I use a pretty hefty command to pass to the command line which triggers Docker to wait for any feedback from nvim-dap
:
docker-compose -f "./docker-compose.yml" exec -T -w /usr/src/app debug python -m debugpy --listen ' ..
debug_host .. ':' .. debug_port .. ' --wait-for-client -m pytest ' .. test_method[1]
Where test_method
is the test name for the nearest test (something I pinched from vim-test
). Using the instructions in the vim-ultest
docs, combined with my previous setup, I form the following:
require("ultest").setup({
builders = {
['python#pytest'] = function(cmd)
local debug_host = '0.0.0.0'
local debug_port = 5678
local test_method = fn['test#python#pytest#build_position']('nearest', {
file = fn['expand']('%'),
line = fn['line']('.'),
col = fn['col']('.')
})
local args = 'docker-compose -f "./docker-compose.yml" exec -T -w /usr/src/app debug python -m debugpy --listen ' .. debug_host .. ':' .. debug_port .. ' --wait-for-client -m pytest ' .. test_method[1]
return {
dap = {
type = "python",
request = "attach",
connect = {
host = debug_host,
port = debug_port
},
args = args,
mode = "remote",
name = "Remote Attached Debugger",
cwd = fn.getcwd(),
pathMappings = {{
localRoot = fn.getcwd(), -- Wherever your Python code lives locally.
remoteRoot = "/usr/src/app" -- Wherever your Python code lives in the container.
}}
}
}
end
}
})
When I run this with UltestDebugNearest
I get Invalid adapter: nil
which is an nvim-dap
error. Which seems odd as I use it with nvim-dap
in my previous setup.
Is there anything obvious I may be overlooking? Granted I need to actually make use of the vim-ultest
cmd
function to pass to nvim-dap
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (8 by maintainers)
That’s great to hear! 😁 As an alternative to the wait, could you add the
-d
flag to the exec command to detach? If that works OK (provided debugpy doesn’t require an interactive session for some reason) then it should be as simple as swappingwith
which will block until it returns.
I’d definitely like to add this to the wiki btw!
So I’m not too familiar with the docker side of nvim-dap but to me it looks like config you’re returning to vim-ultest is the wrong one.
From what I can tell you should be running your docker command as a separate job (using
vim.loop.spawn
,jobstart
or whatever) and then return thepythonAttachConfig
from the example in the docs. So it’d be something like