File tree Expand file tree Collapse file tree 3 files changed +29
-26
lines changed
Expand file tree Collapse file tree 3 files changed +29
-26
lines changed Original file line number Diff line number Diff line change @@ -77,8 +77,9 @@ can install it manually using either:
7777 - Use ` :lua require('dap-python').test_method() ` to debug the closest method above the cursor.
7878
7979 Supported test frameworks are ` unittest ` , ` pytest ` and ` django ` . By default it
80- tries to detect the runner by probing for ` pytest.ini ` and ` manage.py ` , if
81- neither are present it defaults to ` unittest ` .
80+ tries to detect the runner by probing for presence of ` pytest.ini ` or
81+ ` manage.py ` , or for a ` tool.pytest ` directive inside ` pyproject.toml ` , if
82+ none are present it defaults to ` unittest ` .
8283
8384 To configure a different runner, change the ` test_runner ` variable. For
8485 example, to configure ` pytest ` set the test runner like this in your
Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ Python extension for nvim-dap *dap-python*
33
44M.test_runner *dap-python.test_runner*
55 Test runner to use by default.
6- The default value is dynamic and depends on `pytest.ini` or `manage.py ` markers.
7- If neither is found "unittest" is used. See | dap-python.test_runners |
6+ The default value is dynamic and depends on `pytest.ini` , `manage.py ` or `pyproject.toml ` markers.
7+ If none are found "unittest" is used. See | dap-python.test_runners |
88 Override this to set a different runner:
99 ```
1010 require('dap-python').test_runner = "pytest"
Original file line number Diff line number Diff line change @@ -22,28 +22,6 @@ M.test_runner = nil
2222M .resolve_python = nil
2323
2424
25- local function default_runner ()
26- if uv .fs_stat (' pytest.ini' ) then
27- return ' pytest'
28- elseif uv .fs_stat (' manage.py' ) then
29- return ' django'
30- elseif uv .fs_stat (" pyproject.toml" ) then
31- local f = io.open (" pyproject.toml" )
32- if f then
33- for line in f :lines () do
34- if line :find (" %[tool.pytest" ) then
35- f :close ()
36- return " pytest"
37- end
38- end
39- f :close ()
40- end
41- return ' unittest'
42- else
43- return ' unittest'
44- end
45- end
46-
4725--- Table to register test runners.
4826--- Built-in are test runners for unittest, pytest and django.
4927--- The key is the test runner name, the value a function to generate the
@@ -88,6 +66,30 @@ local function roots()
8866end
8967
9068
69+ local function default_runner ()
70+ for root in roots () do
71+ if uv .fs_stat (root .. " /pytest.ini" ) then
72+ return " pytest"
73+ elseif uv .fs_stat (root .. " /manage.py" ) then
74+ return " django"
75+ elseif uv .fs_stat (root .. " /pyproject.toml" ) then
76+ local f = io.open (root .. " /pyproject.toml" )
77+ if f then
78+ for line in f :lines () do
79+ if line :find (" %[tool.pytest" ) then
80+ f :close ()
81+ return " pytest"
82+ end
83+ end
84+ f :close ()
85+ end
86+ end
87+ end
88+
89+ return " unittest"
90+ end
91+
92+
9193local get_python_path = function ()
9294 local venv_path = os.getenv (' VIRTUAL_ENV' )
9395 if venv_path then
You can’t perform that action at this time.
0 commit comments