diff --git a/README.md b/README.md index 4fb6a89..8623672 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,12 @@ require("neotest").setup({ -- Runner to use. Will use pytest if available by default. -- Can be a function to return dynamic value. 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, }) } diff --git a/lua/neotest-python/init.lua b/lua/neotest-python/init.lua index cd90045..bc8ee8e 100644 --- a/lua/neotest-python/init.lua +++ b/lua/neotest-python/init.lua @@ -11,6 +11,7 @@ end local python_script = (Path.new(script_path()):parent():parent() / "neotest.py").filename local dap_args +local is_test_file = base.is_test_file local function get_strategy_config(strategy, python, program, args) local config = { @@ -66,7 +67,7 @@ PythonNeotestAdapter.root = lib.files.match_root_pattern( ) function PythonNeotestAdapter.is_test_file(file_path) - return base.is_test_file(file_path) + return is_test_file(file_path) end ---@async @@ -115,12 +116,7 @@ function PythonNeotestAdapter.build_spec(args) python_script, script_args, }) - local strategy_config = get_strategy_config( - args.strategy, - python, - python_script, - script_args - ) + local strategy_config = get_strategy_config(args.strategy, python, python_script, script_args) return { command = command, context = { @@ -153,6 +149,7 @@ end setmetatable(PythonNeotestAdapter, { __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 get_args = opts.args elseif opts.args then