Closed ramboman closed 2 months ago
Thanks for providing that much detail. I reproduced the steps in a docker container and found this in ~/.local/state/nvim/neotest.log
INFO | 2024-06-22T10:41:44Z+0100 | ...al/share/nvim/lazy/neotest/lua/neotest/adapters/init.lua:18 | Found 1 adapters for directory /home/ubuntu/pytest_example
DEBUG | 2024-06-22T10:41:44Z+0100 | ...al/share/nvim/lazy/neotest/lua/neotest/adapters/init.lua:19 | Adapters: { {
adapter = {
build_spec = <function 1>,
discover_positions = <function 2>,
filter_dir = <function 3>,
is_test_file = <function 4>,
name = "neotest-bash",
results = <function 5>,
root = <function 6>
},
root = "/home/ubuntu/pytest_example"
} }
Neotest is using adapter.root function in the process of chosing adapters. So this bug takes place because of:
I tried adding ".git" at the end of the neotest-python list of root matchers and it worked for me.
I think you could open a PR/issue on their repo to add it.
Here is how to reproduce the problem:
nvim
files (.cache, .local/state, .local/share, .config, etc)vim.g.mapleader = " " -- Make sure to set
mapleader
before lazy so your mappings are correct vim.g.maplocalleader = "\" -- Same formaplocalleader
-- Install packages require("lazy").setup({ { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", config = function () local configs = require("nvim-treesitter.configs")
}, { "nvim-neotest/neotest", dependencies = { "nvim-neotest/nvim-nio", "nvim-lua/plenary.nvim", "antoinemadec/FixCursorHold.nvim", "nvim-treesitter/nvim-treesitter", "nvim-neotest/neotest-python", "rcasia/neotest-bash", }, keys = { {"t", "", desc = "+test"},
{ "tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Run File" },
{ "tT", function() require("neotest").run.run(vim.uv.cwd()) end, desc = "Run All Test Files" },
{ "tr", function() require("neotest").run.run() end, desc = "Run Nearest" },
{ "tl", function() require("neotest").run.run_last() end, desc = "Run Last" },
{ "ts", function() require("neotest").summary.toggle() end, desc = "Toggle Summary" },
{ "to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Show Output" },
{ "tO", function() require("neotest").outputpanel.toggle() end, desc = "Toggle Output Panel" },
{ "tS", function() require("neotest").run.stop() end, desc = "Stop" },
{ "tw", function() require("neotest").watch.toggle(vim.fn.expand("%")) end, desc = "Toggle Watch" },
},
opts = function()
return {
-- your neotest config here
adapters = {
require("neotest-python"),
--require("neotest-bash"),
},
}
end,
config = function( , opts)
-- get neotest namespace (api call creates or returns namespace)
local neotest_ns = vim.api.nvim_create_namespace "neotest"
vim.diagnostic.config({
virtual_text = {
format = function(diagnostic)
local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", "")
return message
end,
},
}, neotest_ns)
require("neotest").setup(opts)
end,
},
})
nvim
, a python file which contains test functions<leader>tr
Result:
neotest-python
worksnvim
--require("neotest-bash")
in.config/nvim/init.lua
nvim
, a python file which contains test functions<leader>tr
Result:
nvim
printsNo tests found