nvim-neotest / neotest

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

[BUG] no such file or directory, when running test on Windows #268

Open janislaus opened 1 year ago

janislaus commented 1 year ago

Great plugin! I'm using neotest together with neotest-python. Everything works fine on Ubuntu, but not on Windows.

NeoVim Version NVIM v0.9.1 Describe the bug Trying to run a test on Windows results in the following log message in neotest.log:

ERROR | 2023-07-04T17:07:38Z+0200 | ...te\pack\packer\start\neotest/lua/neotest/client/init.lua:311 | Couldn't find positions in path C:\Users\myUserName\projects\foo\tests\test_neotest.py ...ck\packer\start\neotest/lua/neotest/lib/process/init.lua:41: ENOENT: no such file or directory
stack traceback:
    [C]: in function 'error'
    ...ck\packer\start\neotest/lua/neotest/lib/process/init.lua:41: in function 'run'
    ...\packer\start\neotest-python/lua/neotest-python/base.lua:17: in function 'module_exists'
    ...\packer\start\neotest-python/lua/neotest-python/init.lua:63: in function 'get_runner'
    ...\packer\start\neotest-python/lua/neotest-python/init.lua:114: in function 'discover_positions'
    ...te\pack\packer\start\neotest/lua/neotest/client/init.lua:302: in function <...te\pack\packer\start\neotest/lua/neotest/client/init.lua:266>
    [C]: in function 'xpcall'
    ...te\pack\packer\start\neotest/lua/neotest/client/init.lua:266: in function '_update_positions'
    ...te\pack\packer\start\neotest/lua/neotest/client/init.lua:319: in function <...te\pack\packer\start\neotest/lua/neotest/client/init.lua:317>

It says that the file does not exist, but it definitely does. This is the test I'm trying to run: image The project foo is located at C:\Users\myUserName\projects

This is my neotest configuration:

require("neotest").setup({
    adapters = {
        require("neotest-python")
    },
    benchmark = {
        enabled = true
    },
    consumers = {},
    default_strategy = "integrated",
    diagnostic = {
        enabled = true,
        severity = 1
    },
    discovery = {
        concurrent = 0,
        enabled = true
    },
    floating = {
        border = "rounded",
        max_height = 0.6,
        max_width = 0.6,
        options = {}
    },
    highlights = {
        adapter_name = "NeotestAdapterName",
        border = "NeotestBorder",
        dir = "NeotestDir",
        expand_marker = "NeotestExpandMarker",
        failed = "NeotestFailed",
        file = "NeotestFile",
        focused = "NeotestFocused",
        indent = "NeotestIndent",
        marked = "NeotestMarked",
        namespace = "NeotestNamespace",
        passed = "NeotestPassed",
        running = "NeotestRunning",
        select_win = "NeotestWinSelect",
        skipped = "NeotestSkipped",
        target = "NeotestTarget",
        test = "NeotestTest",
        unknown = "NeotestUnknown"
    },
    icons = {
        child_indent = " ",
        child_prefix = " ",
        collapsed = ">",
        expanded = "v",
        failed = "X",
        final_child_indent = " ",
        final_child_prefix = " ",
        non_collapsible = " ",
        passed = "",
        running = "",
        running_animated = { "/", "|", "\\", "-", "/", "|", "\\", "-" },
        skipped = "",
        unknown = ""
    },
    jump = {
        enabled = true
    },
    log_level = 3,
    output = {
        enabled = true,
        open_on_run = "short"
    },
    output_panel = {
        enabled = true,
        open = "botright split | resize 15"
    },
    projects = {},
    quickfix = {
        enabled = true,
        open = true
    },
    run = {
        enabled = true
    },
    running = {
        concurrent = true
    },
    state = {
        enabled = true
    },
    status = {
        enabled = true,
        signs = true,
        virtual_text = false
    },
    strategies = {
        integrated = {
            height = 40,
            width = 120
        }
    },
    summary = {
        animated = true,
        enabled = true,
        expand_errors = true,
        follow = true,
        mappings = {
            attach = "a",
            clear_marked = "M",
            clear_target = "T",
            debug = "d",
            debug_marked = "D",
            expand = { "<CR>", "<2-LeftMouse>" },
            expand_all = "e",
            jumpto = "i",
            mark = "m",
            next_failed = "J",
            output = "o",
            prev_failed = "K",
            run = "r",
            run_marked = "R",
            short = "O",
            stop = "u",
            target = "t"
        },
        open = "botright vsplit | vertical resize 50"
    }
})

Expected behavior Neotest does recognize that test_neotest.py is actually a file, in which there is a test.

xchray commented 5 months ago

I have same issue in windows 11, though vscode has no issue.

shahverd commented 2 months ago

I have a similar problem on windows, while on linux it works perfectly fine.

GitMurf commented 2 weeks ago

FYI everyone it is typically a Windows path issue as well as often you need to point to the .CMD version of the executable if you are doing something like accessing node modules for vitest, jest etc.

I am not sure about python but generally speaking you need to hardcode to your test runner executable with a path like I have below (this is what I use for vitest).

  1. need to be backslashes instead of forward
  2. need to be double backslashes
  3. need to have .CMD on the end otherwise it tries to run the unix version of the command
  adapters = {
      require('neotest-vitest')({
        vitestCommand = 'node_modules\\.bin\\vitest.CMD',
      })
  }