nvim: Add coverage support for python testing
Use `,tp` to load a coverage report and show it in the gutter. Use `,tP` to toggle it off and on. Use `,ts` to show a summary instead.
This commit is contained in:
parent
497b19fcbe
commit
23793795d6
1 changed files with 50 additions and 6 deletions
|
@ -102,14 +102,15 @@ return {
|
|||
config = function()
|
||||
require("neotest").setup({
|
||||
adapters = {
|
||||
require("neotest-python"),
|
||||
require("neotest-python")({
|
||||
-- with coverage requires coverage.py and pytest-cov installed
|
||||
args = { "--cov" },
|
||||
}),
|
||||
},
|
||||
})
|
||||
for _, v in pairs(require("lazy").plugins()) do
|
||||
if v[1] == "folke/which-key.nvim" then
|
||||
require("which-key").register({ ["<localleader>t"] = { name = "+test" } })
|
||||
break
|
||||
end
|
||||
local status, wk = pcall(require, "which-key")
|
||||
if status then
|
||||
wk.register({ ["<localleader>t"] = { name = "+test" } })
|
||||
end
|
||||
end,
|
||||
keys = {
|
||||
|
@ -169,4 +170,47 @@ return {
|
|||
},
|
||||
},
|
||||
},
|
||||
-- TODO needs to pick up poetry env for python,
|
||||
-- currently just hard-codes running through poetry
|
||||
{
|
||||
"andythigpen/nvim-coverage",
|
||||
dependencies = {
|
||||
"nvim-lua/plenary.nvim",
|
||||
},
|
||||
config = function()
|
||||
require("coverage").setup({
|
||||
lang = { python = { coverage_command = "poetry run coverage json -q -o -" } } ,
|
||||
})
|
||||
end,
|
||||
cmd = {
|
||||
"Coverage",
|
||||
"CoverageLoad",
|
||||
"CoverageLoadLcov",
|
||||
"CoverageShow",
|
||||
"CoverageHide",
|
||||
"CoverageToggle",
|
||||
"CoverageClear",
|
||||
"CoverageSummary",
|
||||
},
|
||||
keys = {
|
||||
{
|
||||
"<localleader>tp",
|
||||
[[<cmd>Coverage<cr>]],
|
||||
desc = "show coverage report",
|
||||
silent = true,
|
||||
},
|
||||
{
|
||||
"<localleader>tP",
|
||||
[[<cmd>CoverageToggle<cr>]],
|
||||
desc = "toggle coverage gutter",
|
||||
silent = true,
|
||||
},
|
||||
{
|
||||
"<localleader>ts",
|
||||
[[<cmd>CoverageSummary<cr>]],
|
||||
desc = "show coverage summary",
|
||||
silent = true,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue