Closed PhilippFeO closed 10 months ago
Time passed and I have figured it out. I had to add the following to my config:
require('dap').configurations.python = {
{
name = "Pytest: Current File",
type = "python",
request = "launch",
module = "pytest",
args = {
"${file}",
"-sv",
-- "--log-cli-level=INFO",
-- "--log-file=test_out.log"
},
console = "integratedTerminal",
}
}
I was also able to reproduce my issue above on non-test methods. dap.continue()
runs the file, ie. debugging a method doesn't work if it is not called, fi. in a if __name__ == '__main__':
block. dap.test_method()
does what I expected from dap.continue()
. Although spending a decent amount of time on informing about debugging in Neovim (YouTube, docs). This was not obvious to me – but makes sense now (like everything makes sense retrospectively). And to be honest, when my issue arised, I hadn't perfect working examples – again, obvious retrospectively.
I will leave this issue open in case some flaws arise since I am still exploring the plugin and don't feel confident enough. You can either close the issue, when I provided the correct solution. Otherwise, I will do it next week. And again, thank you for making debugging in Neovim possible :rocket:
The default "Launch file" configuration from nvim-dap-python will run the file similarly to if it would've been launched in the command line via python <myfile>.py
, so if you use it on a test module it won't work unless it has an entry point.
E.g. for plain unittest
you could import the main function and call that within a if __name__ == '__main__':
block (https://docs.python.org/3/library/unittest.html#unittest.main)
But your solution to add a dedicated pytest configuration is also fine and has the advantage that it works without changes to pytest files
Thank you for answering such a beginners question :)
Hey,
I recently set up nvim-dap and nvim-dap-python and everything works fine on normal Python files.
When I want to debug a pytest test function with
dap.continue()
it starts, ie.dap-ui
loads but everything is terminated after a short flash of the UI printing 'Session terminated'. In contrast, invoking withdap.test_method()
does the job, ie.dap-ui
loads and the program halts on the breakpoint. Any hints are welcome!My configuration
nvim-dap-python
I have no
pytest.ini
in my project.pip list
I tinkered around with different virtual environments. Here is the one of the project I wish to be able to debug with. (To be honest, currently it is not obvious to me when
nvim-dap-python
finds the virtual env via$VIRTUAL_ENV
itself and when not.)And also
pip list
of~/.venv/debugpy/bin/activate
:I hope these information are sufficient. Let me know, in case you need more!
Thank you for your work!