nvim-neotest / neotest

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

[BUG] Using `:lcd` in other tabs causes other project tests to show in the original summary window #327

Open onezeroecho opened 10 months ago

onezeroecho commented 10 months ago

NeoVim Version

Output of nvim --version:

NVIM v0.9.4
Build type: Release
LuaJIT 2.1.1692716794

Describe the bug

Using the :lcd command in other windows or tabs shows discovered tests in the original summary window.

This affects workflows where multiple tabs and windows are used for different projects and the original tab with the summary window starts to get polluted with tests from other project directories.

To Reproduce

  1. Install and add the neotest-python adapter to the standard minimal.lua configuration
  2. Create the /tmp/parent/{project1,project2} directory structure with separate test files underneath the project1 and project2 directories:
    
    mkdir -p /tmp/parent/project2
    cd /tmp/parent/project2
    vi test_strings.py

mkdir -p /tmp/parent/project1 cd /tmp/parent/project1 nvim --clean -u /tmp/minimal.lua test_math.py


3. Run the `:NeotestSummary` command and view the summary window:
```text
neotest-python
╰╮ test_math.py
 ╰╮ TestMathFunctions
  ├─ test_addition
  ├─ test_subtraction
  ╰─ test_multiply
  1. Create a new tab with :tabnew
  2. In the new tab run :lcd ../project2 to move to the other project directory
  3. Move back to the original tab and notice how the other tests appear:
    
    neotest-python
    ╰╮ test_math.py
    ╰╮ TestMathFunctions
    ├─ test_addition
    ├─ test_subtraction
    ╰─ test_multiply

neotest-python /tmp/parent/project2 ╰─ test_strings.py



**Expected behavior**

The original tab with the summary window for `project1/test_math.py` shouldn't change when other tabs change their working directory with `:lcd`.

**Logs**

The `neotest.log` is empty during the above testing.
rcarriga commented 9 months ago

This is the intended behaviour. The summary window will show all tests that it is aware of, it does not filter based on the current directory

onezeroecho commented 9 months ago

@rcarriga I should mention that this behavior also causes duplicates of the same project even when just doing :lcd ../, which gives me the following in the summary window:

neotest-python
project1
╰╮ test_math.py
 ╰╮ TestMathFunctions
  ├─ test_addition
  ├─ test_subtraction
  ╰─ test_multiply

neotest-python
├─ project1

Originally I thought discovery = { enabled = false } would have fixed this, but I understood the parameter wrong.

Do you think there will ever be a setting or toggle that be able to change this default behavior? Or perhaps a command to only explicitly discover tests at a user-inputted path?