Skip to content
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

Feature request - Add tab completion for test classes and functions #7329

Open
timhoffm opened this issue Jun 5, 2020 · 8 comments
Open
Labels
type: enhancement new feature or API change, should be merged into features branch

Comments

@timhoffm
Copy link
Contributor

timhoffm commented Jun 5, 2020

Pytest can tab-complete for running individual files

pytest path_to/test_file.py

It would be great to extend the completion to classes and functions

pytest path_to/test_file.py::test_function

pytest path_to/test_file.py::TestClass::test_method

AFAICS it should be relatively straight forward to extend FastFilesCompleter for that. I may get around implemting this at some point.
Question: would it be ok for the completer to import the test_file.py or should we parse the contents via AST?

@nicoddemus
Copy link
Member

Hi @timhoffm!

I think AST should be preferred, as importing files always has the chance of executing side-effects. 👍

@nicoddemus nicoddemus added the type: enhancement new feature or API change, should be merged into features branch label Jun 5, 2020
@RonnyPfannschmidt
Copy link
Member

Without import we can only handle simple cases

@nicoddemus
Copy link
Member

Indeed, tests generated at runtime would not be found then.

@timhoffm
Copy link
Contributor Author

timhoffm commented Jun 9, 2020

From my experience, generated tests are a niche application, but YMMV. It would not be the end of the world if tab completion cannot find them 😄.

OTOH pytest will import the modules for test discovery. Side effects will be run then anyway. The only reason I see for not import for completion would be that such side effects could be slow and thus slow down the completer.

@RonnyPfannschmidt
Copy link
Member

for tab completion i would propose to simply import and collect once
also gies a good reason to make collection performance better

@bhrutledge
Copy link

Could this be related to #5514?

Also, possibly related: I've pondered how to select tests to run via fuzzy autocompletion, maybe building on fzf. I think that would require a cache of collected tests. Without looking at the current autocomplete implementation, I wonder if that cache could be useful for this issue as well.

@timhoffm
Copy link
Contributor Author

timhoffm commented Jun 11, 2020

Yes, this is essentially the same as #5514.

@dbaty
Copy link

dbaty commented Aug 20, 2020

I've pondered how to select tests to run via fuzzy autocompletion, maybe building on fzf.

@bhrutledge : for what it's worth, I wrote a small program (brilliantly named testfinder) that helps me do that. Basically, it parses all Python test files and prints pytest-compatible "paths" for all test classes, methods and functions. You can then feed that to fzf and voilà, you have fzf-powered auto-completion for pytest. It's a bit rough (using regexps, not reading the AST) but it works well enough. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement new feature or API change, should be merged into features branch
Projects
None yet
Development

No branches or pull requests

5 participants