nvim/lua/custom/plugins/neotest.lua
Jeremie Fraeys a8c06ae101
Some checks failed
Luacheck / luacheck (push) Failing after 9s
StyLua / stylua (push) Successful in 2s
fix: configure neotest-python for tests/ directory discovery
2026-02-08 17:04:49 -05:00

96 lines
2.8 KiB
Lua

return {
{
'nvim-neotest/neotest',
dependencies = {
'nvim-lua/plenary.nvim',
'nvim-neotest/nvim-nio',
'nvim-treesitter/nvim-treesitter',
'nvim-neotest/neotest-python',
'alfaix/neotest-gtest',
'andythigpen/nvim-coverage',
},
event = 'VeryLazy',
config = function()
local neotest = require('neotest')
neotest.setup({
adapters = {
require('neotest-python')({
runner = 'pytest',
dap = { justMyCode = false },
args = { '-v', '--tb=short' },
-- Discover tests in tests/ directory
pytest_discover_instances = true,
}),
require('neotest-gtest').setup({
debug_adapter = 'codelldb',
}),
},
output = { open_on_run = false },
summary = { open = 'botright vsplit | vertical resize 60' },
})
local ok_cov, coverage = pcall(require, 'coverage')
if ok_cov then
coverage.setup({
auto_reload = true,
})
end
-- Keymaps (defined after setup to ensure modules are available)
vim.keymap.set('n', '<leader>tn', function()
neotest.run.run()
end, { desc = 'Test: Run nearest' })
vim.keymap.set('n', '<leader>tf', function()
neotest.run.run(vim.fn.expand('%'))
end, { desc = 'Test: Run file' })
vim.keymap.set('n', '<leader>ta', function()
neotest.run.run(vim.fn.getcwd())
end, { desc = 'Test: Run all (cwd)' })
vim.keymap.set('n', '<leader>td', function()
neotest.run.run({ strategy = 'dap' })
end, { desc = 'Test: Debug nearest' })
vim.keymap.set('n', '<leader>tx', function()
neotest.run.stop()
end, { desc = 'Test: Stop' })
vim.keymap.set('n', '<leader>ts', function()
neotest.summary.toggle()
end, { desc = 'Test: Toggle summary' })
vim.keymap.set('n', '<leader>to', function()
neotest.output.open({ enter = true, auto_close = false })
end, { desc = 'Test: Show output' })
vim.keymap.set('n', '<leader>tw', function()
neotest.watch.toggle(vim.fn.expand('%'))
end, { desc = 'Test: Watch file' })
vim.keymap.set('n', ']t', function()
neotest.jump.next({ status = 'failed' })
end, { desc = 'Test: Next failed' })
vim.keymap.set('n', '[t', function()
neotest.jump.prev({ status = 'failed' })
end, { desc = 'Test: Prev failed' })
vim.keymap.set('n', '<leader>tC', function()
local ok, cov = pcall(require, 'coverage')
if ok then
cov.toggle()
end
end, { desc = 'Test: Toggle coverage' })
vim.keymap.set('n', '<leader>tL', function()
local ok, cov = pcall(require, 'coverage')
if ok then
cov.load(true)
end
end, { desc = 'Test: Load coverage' })
end,
},
}