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:
Daniel Watkins
2022-11-10 03:41:54 -05:00
committed by GitHub
parent 52624d1306
commit 16c3c90b55

View File

@@ -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
;; Match decorated classes, including decorators in definition
(decorated_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 (class_definition
name: (identifier) @namespace.name) name: (identifier) @namespace.name)
@namespace.definition @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)