Skip to content

Commit

Permalink
Fix neotest-python plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
olisikh committed Jan 3, 2025
1 parent fb10766 commit 6c83287
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion nix/nixvim/extra-config/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
require('scala-zio-quickfix').setup({});
''
)
+ import ./harpoon.lua.nix
+ import ./harpoon.lua.nix
8 changes: 8 additions & 0 deletions nix/nixvim/keymaps/neotest.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@
desc = "neotest: jump to next failed test";
};
}
{
key = "<leader>tS";
action = ":lua require('neotest').summary.toggle()<cr>";
mode = "n";
options = {
desc = "neotest: [t]est [S]ummary";
};
}
]
34 changes: 25 additions & 9 deletions nix/nixvim/plugins/neotest.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ let
hash = "sha256-RFEPtWPVHKehfc6PMF6ya0UaDpFIJDD8bFG8xwXPpsk=";
};
});

neotest-python = (pkgs.vimUtils.buildVimPlugin {
name = "neotest-python";
src = pkgs.fetchFromGitHub {
owner = "olisikh";
repo = "neotest-python";
rev = "fix/no_tests_found";
hash = "sha256-Fk+hMsDYPg48R0f52xOdr0X1+JmwciuRoMtMEsnA8L0=";
};
});
in
{
neotest = {
Expand All @@ -27,6 +37,7 @@ in
adapters = {
python = {
enable = true;
package = neotest-python;
settings = {
args = [ "-s" ];
pytest_discover_instances = true;
Expand All @@ -38,28 +49,32 @@ in
return false
end
local file = io.open(file_path, 'r')
-- NOTE: check if there the file is starting or ending with test keyword
local path_segments = vim.split(file_path, "/")
local file_name = path_segments[#path_segments]
if vim.startswith(file_name, "test_") then
return true
elseif vim.endswith(file_name, "_test.py" ) then
return true
end
local file = io.open(file_path, "r")
if file == nil then
return false
end
local content = file:read('a')
local content = file:read("a")
file:close()
if content == nil then
return false
end
local has_tests = content:match('def test')
-- NOTE: check if there are functions that start with test_
if content:match('def test_') then
if content:match("def test_") then
return true
end
-- NOTE: check if there are files starting or ending with test
local path_segments = vim.split(file_path, "/")
local file_name = elems[#path_segments]
return vim.startswith(file_name, "test_") or vim.endswith(file_name, "_test.py")
return false
end
'';
};
Expand All @@ -73,6 +88,7 @@ in
java.enable = true;
vitest.enable = true;
jest.enable = true;
# gradle.enable = true; # TODO: check out this plugin, maybe it's a nice universal plugin to run even kotlin tests?
};
};
}

0 comments on commit 6c83287

Please sign in to comment.