nvim-neotest / neotest-python

MIT License
126 stars 38 forks source link

How to set working directory for unittest in neotest setup? #19

Closed akvilary closed 1 year ago

akvilary commented 1 year ago

Case: I have tests in repo, but iI need to run it in different directory. It seems as cwd in adapter setup does not work. I also have tried to put cwd to adapters = dap = {cwd = 'path_here'} (it is also not worked)

local neotest = require("neotest")
neotest.setup({
  adapters = {
    require("neotest-python")({
        python = "/opt/python3.7/bin/python3.7",
        runner = "unittest",
        cwd = '/tmp/tests/mega_project/tests/stateless/run',
    })
  },
})

local envs = {}
envs['LD_LIBRARY_PATH'] = '.'
envs['PYTHONPATH'] = '$PYTHONPATH:/home/user/repos/some_project'

local run_test = function()
    require("neotest").run.run({
        strategy = "dap",
        env = envs
    })
end

vim.keymap.set('n', '<F4>', run_test)
rcarriga commented 1 year ago

There is no cwd setting for neotest-python, it's agnostic to the project location. All paths are passed in from the core plugin.

You can pass cwd to the run function: require("neotest").run.run({ cwd = ... })