-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Discover pytest fixtures through imports #1786
Comments
This is definitely possible. It's mainly a performance question/issue. I would myself be happy to have this changed. We might just want to follow direct imports, but not other things. In general it's definitely possible to use it for goto, but for completions, we might need to reconsider it, because of potential speed issues (especially for large projects). It's a bit unfortunate, but I have been making a lot of these kind of decisions to avoid performance issues. However, I'm currently rewriting Jedi in Rust (with a lot of builtin type caching). I hope that that will eventually fix the issue for people like you. But feel free to play around with this issue. |
But: Feel free to work on this and get it working. Now that I'm reading the code I'm pretty sure that |
I looked at the code, and while I don't claim to fully understand it, it does not look like I noticed that:
I'm not sure which of the two should be fixed. I don't think it's a problem in |
My idea was to allow Star imports are a different beast altogether and I'm pretty sure that it's not a good idea to to follow those for performance reasons. |
I'm not sure I understand. def complete_param_names(func):
def wrapper(context, func_name, decorator_nodes):
module_context = context.get_root_context()
if _is_pytest_func(func_name, decorator_nodes):
names = []
for module_context in _iter_pytest_modules(module_context):
names += FixtureFilter(module_context).values()
if names:
return names
return func(context, func_name, decorator_nodes)
return wrapper (it is also used in So let's say we have this: import pytest
from some_module_that_defines_fixtures import foo
@pytest.fixture
def bar():
pass
def test_main():
pass And we are trying to complete arguments for
|
Sorry my bad. You are of course right. The thing that needs improvement is the |
How? I tried putting some prints into |
As I wrote before, star imports are out of scope for this one (for performance reasons). However with normal imports it would work. |
I still don't get why star imports have to be a performance issue. Isn't Jedi already following them for regular completion and introspection? |
It just means there are even more modules to analyze. At least for fixture searching we already do a heuristic that avoids a lot of type inference. I guess I'm a bit annoyed that it's already slow for me and I don't want to get it even slower. But you are probably right that it's not as bad as I think. If there are no star imports in a module it's probably almost a no-op and in case there are, people probably want them in their results. So I guess we could add that as well, even if it makes it a bit slower. |
On big projects you sometimes want to split organize your fixtures in many files. This means importing the fixtures into either
conftest.py
or - for better modularity - into the test file itself.#791 added support for pytest fixtures discovery, but it only looks for fixtures defined directly inside the test file or directly inside
conftest.py
. Is it possible to make it look for fixtures imported into these files, just like it would do with regular completion?The text was updated successfully, but these errors were encountered: