Skip to content

Commit

Permalink
fix: no tests found bug in python files
Browse files Browse the repository at this point in the history
  • Loading branch information
olisikh committed Jan 3, 2025
1 parent a2861ab commit 80c9658
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lua/neotest-python/adapter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,22 @@ return function(config)
return script_args
end

local function get_root(path)
return base.get_root(path) or vim.loop.cwd() or ""
end

local function filter_dir(name)
return name ~= "venv"
end

---@type neotest.Adapter
return {
name = "neotest-python",
root = base.get_root,
filter_dir = function(name)
return name ~= "venv"
end,
root = get_root,
filter_dir = filter_dir,
is_test_file = config.is_test_file,
discover_positions = function(path)
local root = base.get_root(path) or vim.loop.cwd() or ""
local root = get_root(path)

local python_command = config.get_python_command(root)
local runner = config.get_runner(python_command)
Expand All @@ -79,8 +85,7 @@ return function(config)
build_spec = function(args)
local position = args.tree:data()

local root = base.get_root(position.path) or vim.loop.cwd() or ""

local root = get_root(position.path)
local python_command = config.get_python_command(root)
local runner = config.get_runner(python_command)

Expand Down
4 changes: 3 additions & 1 deletion lua/neotest-python/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function M.is_test_file(file_path)
return vim.startswith(file_name, "test_") or vim.endswith(file_name, "_test.py")
end

M.module_exists = function(module, python_command)
function M.module_exists(module, python_command)
return lib.process.run(vim
.iter({
python_command,
Expand All @@ -29,9 +29,11 @@ local python_command_mem = {}
---@return string[]
function M.get_python_command(root)
root = root or vim.loop.cwd()

if python_command_mem[root] then
return python_command_mem[root]
end

-- Use activated virtualenv.
if vim.env.VIRTUAL_ENV then
python_command_mem[root] = { Path:new(vim.env.VIRTUAL_ENV, "bin", "python").filename }
Expand Down

0 comments on commit 80c9658

Please sign in to comment.