feat: custom test file detection

See #3
This commit is contained in:
Rónán Carrigan
2022-06-14 10:16:58 +01:00
parent e8ce1d3047
commit de234d600e
2 changed files with 10 additions and 7 deletions

View File

@@ -27,6 +27,12 @@ require("neotest").setup({
-- Can be a function to return dynamic value. -- Can be a function to return dynamic value.
runner = "pytest", runner = "pytest",
-- Returns if a given file path is a test file.
-- NB: This function is called a lot so don't perform any heavy tasks within it.
is_test_file = function(file_path)
...
end,
}) })
} }
}) })

View File

@@ -11,6 +11,7 @@ end
local python_script = (Path.new(script_path()):parent():parent() / "neotest.py").filename local python_script = (Path.new(script_path()):parent():parent() / "neotest.py").filename
local dap_args local dap_args
local is_test_file = base.is_test_file
local function get_strategy_config(strategy, python, program, args) local function get_strategy_config(strategy, python, program, args)
local config = { local config = {
@@ -66,7 +67,7 @@ PythonNeotestAdapter.root = lib.files.match_root_pattern(
) )
function PythonNeotestAdapter.is_test_file(file_path) function PythonNeotestAdapter.is_test_file(file_path)
return base.is_test_file(file_path) return is_test_file(file_path)
end end
---@async ---@async
@@ -115,12 +116,7 @@ function PythonNeotestAdapter.build_spec(args)
python_script, python_script,
script_args, script_args,
}) })
local strategy_config = get_strategy_config( local strategy_config = get_strategy_config(args.strategy, python, python_script, script_args)
args.strategy,
python,
python_script,
script_args
)
return { return {
command = command, command = command,
context = { context = {
@@ -153,6 +149,7 @@ end
setmetatable(PythonNeotestAdapter, { setmetatable(PythonNeotestAdapter, {
__call = function(_, opts) __call = function(_, opts)
is_test_file = opts.is_test_file or is_test_file
if type(opts.args) == "function" or (type(opts.args) == "table" and opts.args.__call) then if type(opts.args) == "function" or (type(opts.args) == "table" and opts.args.__call) then
get_args = opts.args get_args = opts.args
elseif opts.args then elseif opts.args then