python: Fix identification of runnable tests within decorated test classes (#29688)

Closes #29486

Release Notes:

- python: Fixed identification of runnable test functions within
decorated pytest classes
This commit is contained in:
Ben Kunkle 2025-04-30 13:26:30 -04:00 committed by GitHub
parent 4d934f2884
commit d03d8ccec1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -55,6 +55,7 @@
(#set! tag python-pytest-method) (#set! tag python-pytest-method)
) )
; pytest classes ; pytest classes
( (
(module (module
@ -66,6 +67,22 @@
) )
) )
; decorated pytest classes
(
(module
(decorated_definition
(decorator)+ @_decorator
definition: (class_definition
name: (identifier) @run @_pytest_class_name
(#match? @_pytest_class_name "^Test")
)
)
(#set! tag python-pytest-class)
)
)
; pytest class methods ; pytest class methods
( (
(module (module
@ -73,12 +90,19 @@
name: (identifier) @_pytest_class_name name: (identifier) @_pytest_class_name
(#match? @_pytest_class_name "^Test") (#match? @_pytest_class_name "^Test")
body: (block body: (block
[(decorated_definition
(decorator)+ @_decorator
definition: (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_")
)
)
(function_definition (function_definition
name: (identifier) @run @_pytest_method_name name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test") (#match? @_pytest_method_name "^test")
) @_python-pytest-method
(#set! tag python-pytest-method)
) )
] @_python-pytest-method)
(#set! tag python-pytest-method)
) )
) )
) )
@ -86,22 +110,29 @@
; decorated pytest class methods ; decorated pytest class methods
( (
(module (module
(class_definition (decorated_definition
(decorator)+ @_decorator
definition: (class_definition
name: (identifier) @_pytest_class_name name: (identifier) @_pytest_class_name
(#match? @_pytest_class_name "^Test") (#match? @_pytest_class_name "^Test")
body: (block body: (block
(decorated_definition [(decorated_definition
(decorator)+ @_decorator (decorator)+ @_decorator
definition: (function_definition definition: (function_definition
name: (identifier) @run @_pytest_method_name name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test_") (#match? @_pytest_method_name "^test_")
) )
) )
) @_python-pytest-method (function_definition
name: (identifier) @run @_pytest_method_name
(#match? @_pytest_method_name "^test")
)
] @_python-pytest-method)
(#set! tag python-pytest-method) (#set! tag python-pytest-method)
) )
) )
) )
)
; module main method ; module main method
( (