feat(query): include test decorators in the test definition (#34)
This means that `neotest.run.run` when the cursor is on a test's decorators will run the decorated test (instead of running the previous test in the file, the current behaviour). Fixes: #31
This commit is contained in:
@@ -83,14 +83,31 @@ end
|
|||||||
---@return Tree | nil
|
---@return Tree | nil
|
||||||
function PythonNeotestAdapter.discover_positions(path)
|
function PythonNeotestAdapter.discover_positions(path)
|
||||||
local query = [[
|
local query = [[
|
||||||
|
;; Match undecorated functions
|
||||||
((function_definition
|
((function_definition
|
||||||
name: (identifier) @test.name)
|
name: (identifier) @test.name)
|
||||||
(#match? @test.name "^test"))
|
(#match? @test.name "^test"))
|
||||||
@test.definition
|
@test.definition
|
||||||
|
;; Match decorated function, including decorators in definition
|
||||||
|
(decorated_definition
|
||||||
|
((function_definition
|
||||||
|
name: (identifier) @test.name)
|
||||||
|
(#match? @test.name "^test")))
|
||||||
|
@test.definition
|
||||||
|
|
||||||
(class_definition
|
;; Match decorated classes, including decorators in definition
|
||||||
name: (identifier) @namespace.name)
|
(decorated_definition
|
||||||
@namespace.definition
|
(class_definition
|
||||||
|
name: (identifier) @namespace.name))
|
||||||
|
@namespace.definition
|
||||||
|
;; Match undecorated classes: namespaces nest so #not-has-parent is used
|
||||||
|
;; to ensure each namespace is annotated only once
|
||||||
|
(
|
||||||
|
(class_definition
|
||||||
|
name: (identifier) @namespace.name)
|
||||||
|
@namespace.definition
|
||||||
|
(#not-has-parent? @namespace.definition decorated_definition)
|
||||||
|
)
|
||||||
]]
|
]]
|
||||||
local root = PythonNeotestAdapter.root(path)
|
local root = PythonNeotestAdapter.root(path)
|
||||||
local python = get_python(root)
|
local python = get_python(root)
|
||||||
|
Reference in New Issue
Block a user