-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run decorated test when cursor is on the decorators #31
Comments
I've never touched treesitter queries before, but my first blind guess for functions is a decent approximation: --- a/lua/neotest-python/init.lua
+++ b/lua/neotest-python/init.lua
@@ -91,6 +91,12 @@ function PythonNeotestAdapter.discover_positions(path)
(class_definition
name: (identifier) @namespace.name)
@namespace.definition
+
+ (decorated_definition
+ ((function_definition
+ name: (identifier) @test.name)
+ (#match? @test.name "^test")))
+ @test.definition
]]
local root = PythonNeotestAdapter.root(path)
local python = get_python(root) This annotates the first decorator line, rather than the |
Actually have been meaning to add support for parsing the parameterized tests as well, just haven't had a chance. I put together a PR for neotest-dotnet that did something very similar to what's needed here Issafalcon/neotest-dotnet#20. The core of the change is discussed here nvim-neotest/neotest#24 (reply in thread) where the parsing is customised to run queries after the initial parse, so the initial queries remain the same and then we traverse the tree to check if there are parameters. If you want to have a go at it, happy to help but if not, I'll get around to it myself at some stage 😄 |
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: nvim-neotest#31
This is actually a more general problem than just parametrized tests: I figured out my classes problem: namespaces nest, and my first copy/paste rule meant that two namespaces were being annotated for decorated classes: the definition itself and the decorated definition, with the former nesting inside the latter. I've pushed up #34 which has a proper approach to this. |
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
…test#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: nvim-neotest#31
Currently, with a test file that looks like:
invoking
neotest.run.run
with the cursor on theparametrize
line results intest_one
being run.I would prefer for
test_thing
to be run: that's the test whose definition I'm editing.The text was updated successfully, but these errors were encountered: