diff --git a/lua/neotest-python/base.lua b/lua/neotest-python/base.lua index 0ac3ddd..315bc94 100644 --- a/lua/neotest-python/base.lua +++ b/lua/neotest-python/base.lua @@ -110,6 +110,20 @@ end ---@return string local function scan_test_function_pattern(runner, config, python_command) local test_function_pattern = "^test" + if runner == "pytest" and config.pytest_discovery then + local cmd = vim + .iter({ python_command, M.get_script_path(), "--pytest-extract-test-name-template" }) + :flatten() + :totable() + local _, data = lib.process.run(cmd, { stdout = true, stderr = true }) + + for line in vim.gsplit(data.stdout, "\n", true) do + if string.sub(line, 1, 1) == "{" and string.find(line, "python_functions") ~= nil then + local pytest_option = vim.json.decode(line) + test_function_pattern = pytest_option.python_functions + end + end + end return test_function_pattern end