nvim-neotest / neotest

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

[BUG] [`setup_project`] Adapters fail with "attempt to call upvalue 'strategy' (a nil value)" #248

Closed fnune closed 1 year ago

fnune commented 1 year ago

NeoVim Version

$ nvim --version
NVIM v0.9.0

Describe the bug

I have a main Neovim config that runs this setup for Neotest:

neotest.setup({
  adapters = {
    require('neotest-jest')({}),
    require('neotest-python')({}),
    require('neotest-rust')({}),
  },
})

A project-local .nvim.lua file does this instead:

neotest.setup({
  adapters = {
    require('neotest-jest')({ jestCommand = "yarn workspace @memfault/app-frontend test:jest" }),
    require('neotest-python')({ python = memfault_python_bin }),
  },
})

That works just fine. But when I try to use setup_project instead in the project-local config...

neotest.setup_project(vim.loop.cwd(), {
  adapters = {
    require('neotest-jest')({ jestCommand = "yarn workspace app-frontend test:jest" }),
    require('neotest-python')({ python = python_bin }),
  },
})

...then trying to run a test results in this:

neotest-python: ...e/fausto/.local/share/nvim/lazy/neotest/lua/nio/init.lua:105: The coroutine failed with this message:
...austo/.local/share/nvim/lazy/neotest/lua/nio/control.lua:208: ...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua:38: attempt to call upvalue 'strategy' (a nil value)
stack traceback:
        [C]: in function 'error'
        ...austo/.local/share/nvim/lazy/neotest/lua/nio/control.lua:208: in function 'with'
        ...nvim/lazy/neotest/lua/neotest/client/strategies/init.lua:37: in function 'run'
        ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:129: in function '_run_spec'
        ...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:89: in function <...al/share/nvim/lazy/neotest/lua/neotest/client/runner.lua:88>

This happens with neotest-python as well as with neotest-jest.

Expected behavior

Neotest merges configurations from the main Neovim config and the project-local .nvim.lua config. For things like adapters, Neotest takes the adapter from the project-local config. For other settings, such as:

  quickfix = { open = false },
  output = { open_on_run = false },
  discovery = { concurrent = 1 },

Those can be specified in the main Neovim config setup call for Neotest and they'll be respected in the setup_project call, where they can still be overwritten.

Logs

I found no interesting logs. Basically ends in this:

INFO | 2023-05-10T17:59:17Z+0200 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:20 | Closing child channel
INFO | 2023-05-10T17:59:17Z+0200 | ...l/share/nvim/lazy/neotest/lua/neotest/lib/subprocess.lua:46 | Child process exited
rcarriga commented 1 year ago

Thanks for the report! This should be working now. Turns out it was a long standing bug that happened to be uncovered by some recent changes

fnune commented 1 year ago

Confirming this is now fixed! Thank you very much :)

dbatten5 commented 11 months ago

I seem to be having a similar issue at the moment, here's my config

    local neotest = require("neotest")
    local neotest_python = require("neotest-python")

    neotest.setup({
      adapters = {
        neotest_python,
      },
      output = { open_on_run = true },
    })

    neotest.setup_project("~/projects/work/work-project", {
      adapters = {
        neotest_python({
          args = { "--dc", "WorkProject" },
        }),
      },
      discovery = {
        enabled = false,
      },
    })

The --dc argument that's supposed to be specific to the work-project seems to be bleeding into other projects, e.g. one at ~/projects/personal/personal-project

antonio commented 9 months ago

The --dc argument that's supposed to be specific to the work-project seems to be bleeding into other projects, e.g. one at ~/projects/personal/personal-project

I can confirm that I'm also seeing this behavior. A regression maybe?

qustavo commented 3 weeks ago

same here