debugging 如何使用nvim-dap运行单个python测试?

t1rydlwq  于 2023-04-30  发布在  Python
关注(0)|答案(1)|浏览(191)

这是我的配置为lunarvim,我想运行能够悬停和运行一个单一的测试。
另外,如果是一个django项目,我该如何设置我想要运行的项目命令?目前它只是尝试运行当前文件

-- nvim-dap
require("dap").adapters.python = {
  type = 'executable';
  command = 'python3';
  args = { '-m', 'debugpy.adapter' };
}
require("dap").configurations.python = {
  {
    type = 'python';
    request = 'launch';
    name = "Launch file";
    program = "${file}";
    pythonPath = function()
      return '/usr/bin/python3'
    end;
  },
}

vim.fn.sign_define('DapBreakpoint', { text = '🟥', texthl = '', linehl = '', numhl = '' })
vim.fn.sign_define('DapStopped', { text = '⭐️', texthl = '', linehl = '', numhl = '' })
lvim.keys.normal_mode["<leader>dh"] = "lua require'dap'.toggle_breakpoint()<CR>"
-- lvim.keys.normal_mode["S-k>"] = "lua require'dap'.step_out()<CR>"
-- lvim.keys.normal_mode["S-l>"] = "lua require'dap'.step_into()<CR>"
-- lvim.keys.normal_mode["S-j>"] = "lua require'dap'.step_over()<CR>"
lvim.keys.normal_mode["<leader>ds"] = "lua require'dap'.stop()<CR>"
lvim.keys.normal_mode["<leader>dn"] = "lua require'dap'.continue()<CR>"
lvim.keys.normal_mode["<leader>dk"] = "lua require'dap'.up()<CR>"
lvim.keys.normal_mode["<leader>dj"] = "lua require'dap'.down()<CR>"
lvim.keys.normal_mode["<leader>d_"] = "lua require'dap'.disconnect();require'dap'.stop();require'dap'.run_last()<CR>"
lvim.keys.normal_mode["<leader>dr"] = "lua require'dap'.repl.open({}, 'vsplit')<CR><C-w>l"
lvim.keys.normal_mode["<leader>di"] = "lua require'dap.ui.variables'.hover()<CR>"
lvim.keys.visual_mode["<leader>di"] = "lua require'dap.ui.variables'.visual_hover()<CR>"
lvim.keys.normal_mode["<leader>d?"] = "lua require'dap.ui.variables'.scopes()<CR>"
-- lvim.keys.normal_mode["leader>de"] = "lua require'dap'.set_exception_breakpoints({"all "})<CR>"
lvim.keys.normal_mode["<leader>da"] = "lua require'debugHelper'.attach()<CR>"
lvim.keys.normal_mode["<leader>dA"] = "lua require'debugHelper'.attachToRemote()<CR>"
lvim.keys.normal_mode["<leader>di"] = "lua require'dap.ui.widgets'.hover()<CR>"
lvim.keys.normal_mode["<leader>d?"] = "lua local widgets=require'dap.ui.widgets';widgets.centered_float(widgets.scopes)<CR>"
nr7wwzry

nr7wwzry1#

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",
  }

您可以添加此配置,并在特定测试上放置断点,然后运行它

相关问题