nvim-neotest / neotest

An extensible framework for interacting with tests within NeoVim.
MIT License
2.12k stars 105 forks source link

[BUG] language name error when running any type of python test #384

Open sho-87 opened 3 months ago

sho-87 commented 3 months ago

Error

I get the following error in neotest.log whenever I try to run a single test file or a directory of tests:

WARN | 2024-03-15T23:53:17Z-0700 | ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:164 | CHILD | Error in remote call ...eovim/share/nvim/runtime/lua/vim/treesitter/language.lua:87: '' is not a valid language name
stack traceback:
    [C]: in function 'error'
    ...eovim/share/nvim/runtime/lua/vim/treesitter/language.lua:87: in function 'add'
    ...m/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98: in function 'get_string_parser'
    ...im-data/lazy/neotest/lua/neotest/lib/treesitter/init.lua:119: in function 'get_parse_root'
    ...im-data/lazy/neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
    ...im-data/lazy/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'func'
    ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:156: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:155>
    [C]: in function 'xpcall'
    ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:155: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:154>

all errors in the log file are the same as above, apart from 2 instances of this:

WARN | 2024-03-15T23:26:14Z-0700 | ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:164 | CHILD | Error in remote call error converting argument 4
stack traceback:
    [C]: in function 'rpcnotify'
    ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:126: in function 'notify'
    ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:165: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:162>
    [C]: in function 'error'
    ...eovim/share/nvim/runtime/lua/vim/treesitter/language.lua:87: in function 'add'
    ...m/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:98: in function 'get_string_parser'
    ...im-data/lazy/neotest/lua/neotest/lib/treesitter/init.lua:119: in function 'get_parse_root'
    ...im-data/lazy/neotest/lua/neotest/lib/treesitter/init.lua:160: in function 'parse_positions_from_string'
    ...im-data/lazy/neotest/lua/neotest/lib/treesitter/init.lua:207: in function 'func'
    ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:156: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:155>
    [C]: in function 'xpcall'
    ...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:155: in function <...al/nvim-data/lazy/neotest/lua/neotest/lib/subprocess.lua:154>

Details

nvim --version:

NVIM v0.9.5
Build type: RelWithDebInfo
LuaJIT 2.1.1703942320
Compilation: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe /MD /Zi /O2 /Ob1  -W3 -wd4311 -wd4146 -DUNIT_TESTING -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_WIN32_WINNT=0x0602 -DMSWIN -DINCLUDE_GENERATED_DECLARATIONS -ID:/a/neovim/neovim/.deps/usr/include/luajit-2.1 -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/build/src/nvim/auto -ID:/a/neovim/neovim/build/include -ID:/a/neovim/neovim/build/cmake.config -ID:/a/neovim/neovim/src -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include
-ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include -ID:/a/neovim/neovim/.deps/usr/include

   system vimrc file: "$VIM\sysinit.vim"
  fall-back for $VIM: "C:/Program Files (x86)/nvim/share/nvim"

The project is managed using Poetry and has the following structure. Running poetry run pytest outside of nvim runs fine:

image

Im using lazyvim and have installed neotest using the extras package, but I have also tested this manually with this config:

return {
  {
    "folke/neodev.nvim",
    opts = {
      library = {
        plugins = { "neotest" },
        types = true,
      },
    },
  },
  {
    "nvim-neotest/neotest",
    dependencies = {
      "nvim-lua/plenary.nvim",
      "antoinemadec/FixCursorHold.nvim",
      "nvim-treesitter/nvim-treesitter",
      "nvim-neotest/neotest-go",
      "nvim-neotest/neotest-python",
    },
    opts = {
      default_strategy = "integrated",
      discovery = {
        enabled = true,
      },
      adapters = {
        require("neotest-go"),
        require("neotest-python")({
          runner = "pytest",
          python = "C:\\Users\\simon\\AppData\\Local\\pypoetry\\Cache\\virtualenvs\\herald-of-completion-NCjgh5TX-py3.11\\Scripts",
          -- python = ".venv/bin/python",
        }),
      },
    },
  },
}

all of my venvs are in the default poetry directory (rather than in separate project directories). I activate the relevant venv using venv-selector

it seems that test discovery works fine as the summary window shows them all correctly, just nothing happens (apart from the logged error) when I run require("neotest").run.run(vim.fn.expand("%"))

image

given how often treesitter appears in the log, I also tried recompiling the grammar for python but that didn't fix the problem

Nosterx commented 2 months ago

I'm facing a similar issue now. I managed to trace it back to the filetype detection in the 'plenary/filetype.lua' file. It seems that Plenary's filetype_table was not populated for some reason. The snippet below fixes the issue for Python. in plenary/filetype.lua:8

local filetype_table = {
  extension = { py = "python" },
  file_name = {},
  shebang = {},
}