rcasia / neotest-bash

Neotest adapter for Bash.
MIT License
17 stars 0 forks source link

`neotest-bash` interferes with `neotest-python` #17

Closed ramboman closed 2 months ago

ramboman commented 2 months ago

Here is how to reproduce the problem:

vim.g.mapleader = " " -- Make sure to set mapleader before lazy so your mappings are correct vim.g.maplocalleader = "\" -- Same for maplocalleader

-- Install packages require("lazy").setup({ { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", config = function () local configs = require("nvim-treesitter.configs")

  configs.setup({
    ensure_installed = { "bash", "python" },
    highlight = { enable = true },
    indent = { enable = true },
  })
end

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

- Open `nvim` so it installs all the plugins
- Close `nvim`
- Go to an empty directory where to create a python test project
- Execute this:
```sh
$ git clone https://github.com/ChristianChiarulli/pytest_example.git --depth 1
$ cd pytest_example
$ python3 -m venv ./venv
$ source venv/bin/activate
$ pip install pytest

Result: neotest-python works

Result: nvim prints No tests found

rcasia commented 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"
  } }

See: https://github.com/nvim-neotest/neotest/blob/26ed90509c377d10dbdebd25b7094a886323b32b/lua/neotest/adapters/init.lua#L10-L21

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.

ramboman commented 2 months ago

I made a comment here regarding this problem. It contains a link to a solution from @rcarriga, the project maintainer, as well.

Thank you @rcasia for the help!