Compare commits

...
3 Commits
Author SHA1 Message Date
Itai Bohadana d67479b1fb fix: logs 2026-08-18 16:55:56 +03:00
rcarrigaandItai Bohadana 04d3f707b8 docs: remove nvim-treesitter ref 2026-08-18 16:52:15 +03:00
rcarrigaandItai Bohadana c0c7dc9851 feat: remove plenary 2026-08-18 16:52:15 +03:00
3 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
[Neotest](https://github.com/rcarriga/neotest) adapter for python.
Supports Pytest and unittest test files.
Requires [nvim-treesitter](https://github.com/nvim-treesitter/nvim-treesitter) and the parser for python.
Requires the treesitter parser for python.
```lua
require("neotest").setup({
+8 -9
View File
@@ -1,6 +1,5 @@
local nio = require("nio")
local lib = require("neotest.lib")
local Path = require("plenary.path")
local M = {}
@@ -8,7 +7,7 @@ function M.is_test_file(file_path)
if not vim.endswith(file_path, ".py") then
return false
end
local elems = vim.split(file_path, Path.path.sep)
local elems = vim.split(file_path, lib.files.sep)
local file_name = elems[#elems]
return vim.startswith(file_name, "test_") or vim.endswith(file_name, "_test.py")
end
@@ -35,14 +34,14 @@ function M.get_python_command(root)
end
-- Use activated virtualenv.
if vim.env.VIRTUAL_ENV then
python_command_mem[root] = { Path:new(vim.env.VIRTUAL_ENV, venv_bin, "python").filename }
python_command_mem[root] = { vim.fs.joinpath(vim.env.VIRTUAL_ENV, venv_bin, "python") }
return python_command_mem[root]
end
for _, pattern in ipairs({ "*", ".*" }) do
local match = nio.fn.glob(Path:new(root or nio.fn.getcwd(), pattern, "pyvenv.cfg").filename)
local match = nio.fn.glob(vim.fs.joinpath(root or nio.fn.getcwd(), pattern, "pyvenv.cfg"))
if match ~= "" then
python_command_mem[root] = { (Path:new(match):parent() / venv_bin / "python").filename }
python_command_mem[root] = { vim.fs.joinpath(vim.fs.dirname(match), venv_bin, "python") }
return python_command_mem[root]
end
end
@@ -52,7 +51,7 @@ function M.get_python_command(root)
if success and exit_code == 0 then
local venv = data.stdout:gsub("\r?\n", "")
if venv then
python_command_mem[root] = { Path:new(venv).filename }
python_command_mem[root] = { venv }
return python_command_mem[root]
end
end
@@ -67,7 +66,7 @@ function M.get_python_command(root)
if success and exit_code == 0 then
local venv = data.stdout:gsub("\r?\n", "")
if venv then
python_command_mem[root] = { Path:new(venv, venv_bin, "python").filename }
python_command_mem[root] = { vim.fs.joinpath(venv, venv_bin, "python") }
return python_command_mem[root]
end
end
@@ -80,7 +79,7 @@ function M.get_python_command(root)
{ stdout = true }
)
if success and exit_code == 0 then
python_command_mem[root] = { Path:new(data).filename }
python_command_mem[root] = { data }
return python_command_mem[root]
end
end
@@ -199,7 +198,7 @@ function M.get_runner(python_path)
then
return vim_test_runner
end
local runner = M.module_exists("pytest_", python_path) and "pytest"
local runner = M.module_exists("pytest", python_path) and "pytest"
or M.module_exists("django", python_path) and "django"
or "unittest"
stored_runners[command_str] = runner
+1
View File
@@ -24,6 +24,7 @@ SOCKET_ROOT_DIR = Path("/tmp/neotest-python")
python_socket_path = (
SOCKET_ROOT_DIR / hashlib.sha1(sys.executable.encode()).digest().hex()
)
python_socket_path.parent.mkdir(exist_ok=True,parents=True)
logger = logging.getLogger('neotest-python')
logger.addHandler(WatchedFileHandler(filename=python_socket_path.with_suffix('.log')))