diff --git a/lua/neotest-python/base.lua b/lua/neotest-python/base.lua index f4f8159..600688a 100644 --- a/lua/neotest-python/base.lua +++ b/lua/neotest-python/base.lua @@ -46,20 +46,28 @@ function M.get_python_command(root) end if lib.files.exists("Pipfile") then - local _, data = lib.process.run({ "pipenv", "--py" }, { stdout = true }) - local venv = data.stdout:gsub("\n", "") - if venv then - python_command_mem[root] = { Path:new(venv).filename } - return python_command_mem[root] + local success, _, data = pcall(lib.process.run, { "pipenv", "--py" }, { stdout = true }) + if success then + local venv = data.stdout:gsub("\n", "") + if venv then + python_command_mem[root] = { Path:new(venv).filename } + return python_command_mem[root] + end end end if lib.files.exists("pyproject.toml") then - local _, data = lib.process.run({ "poetry", "env", "info", "-p" }, { stdout = true }) - local venv = data.stdout:gsub("\n", "") - if venv then - python_command_mem[root] = { Path:new(venv, "bin", "python").filename } - return python_command_mem[root] + local success, _, data = pcall( + lib.process.run, + { "poetry", "env", "info", "-p" }, + { stdout = true } + ) + if success then + local venv = data.stdout:gsub("\n", "") + if venv then + python_command_mem[root] = { Path:new(venv, "bin", "python").filename } + return python_command_mem[root] + end end end diff --git a/lua/neotest-python/init.lua b/lua/neotest-python/init.lua index bc8ee8e..944b745 100644 --- a/lua/neotest-python/init.lua +++ b/lua/neotest-python/init.lua @@ -58,13 +58,8 @@ end ---@type neotest.Adapter local PythonNeotestAdapter = { name = "neotest-python" } -PythonNeotestAdapter.root = lib.files.match_root_pattern( - "pyproject.toml", - "setup.cfg", - "mypy.ini", - "pytest.ini", - "setup.py" -) +PythonNeotestAdapter.root = + lib.files.match_root_pattern("pyproject.toml", "setup.cfg", "mypy.ini", "pytest.ini", "setup.py") function PythonNeotestAdapter.is_test_file(file_path) return is_test_file(file_path)