-
Notifications
You must be signed in to change notification settings - Fork 768
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
Don't offer completions / auto-imports for class/function/parameter/import alias names #163
Comments
Hey @anatoly-kor! Just to be clear, what you're describing is that you are seeing a completion that auto-imports the fixture and you wouldn't expect this behaviour? |
Hi @savannahostrowski. Yes! I mean when test(with fixture) is wrote, auto-import add imports, but doesn't must because for pytest not required import fixture modules.
|
Thanks for confirming. In this case, the problem is that completions are offered in some contexts where they don't make sense (parameter, function, and class names). If you're defining a function, we shouldn't try to autocomplete a parameter name (because we would never know what the right names are for a brand new function). |
Seeing the same issue here. Maybe a context could be added to the auto-import feature to disable it when a Overall I must say I've found the auto-import feature to be more of a hurdle than anything else. When an auto-import gets added is usually a duplicate or something I didn't really want, and in most case the module from which I'm adding a class or function is not discovered. It would be nice if the feature could be disable completely. |
If you have feedback about what could be improved with auto-imports in general, we'd appreciate those in a separate issue. If we are offering something that's a duplicate or something you don't want, then that's something to solve. This specific issue is about offering completions for names we can't actually know (brand new funcs/classes/parameters) and would be hit regardless of the auto-import setting.
That is #64, which we plan to do. |
Right, I didn't want to confuse the issue and #64 sounds good. To avoid auto-importing fixtures, something that could be checked is if the object has the attribute |
I like the solution proposed in #178. Today, the setting |
That level of control over completions is not possible in VS Code as it stands now. We return a list of completions given a location in the code, and VS Code displays it. We can't defer this or ask for user input if they want to expand some extra stuff, because this is effectively a request for state where there's only one answer given the current document and location. |
The auto import feature is really useful in most scenarios, however as stated in this issue, it can be a little inconvenient with pytest when you're entering a fixture into your test function's signature and it auto-imports. Pytest does not require you to import its fixtures from a By the design of the pytest library, users use a filename that is always called Is it possible to create an array or object setting to be used in the workspace's For example, VS Code's The setting might look something like: "python.analysis.autoImportExclusions": {
"conftest.py": true,
"**/conftest.py": true,
...
}, |
Before we add any settings, we need to fix this completion context issue and not offer completions in conditions where we can't actually know a name. I wouldn't want to add a setting to work around an issue that we're going to end up fixing anyway (and that setting in particular is not as simple as you might think). |
OK, if PyLance doesn't add auto-imports for pytest fixtures once you've put in the fix, then I'm not worried how that's achieved. If a setting isn't required, then even better! |
This issue has been fixed in version 2020.11.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#2020111-11-november-2020 |
Describe the bug
For tests automatically adds import for fixture. Pytest know where find out fixture(conftest.py), not required make auto import for it.
To Reproduce
conftest.py
with that example code:test_example.py
with that code:Expected behavior
Import for
ExampleFixture
is not addedVS Code extension or command-line
VS Code extension
Version: v2020.7.3
The text was updated successfully, but these errors were encountered: