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

Complete pytest #257

Closed
dbrgn opened this issue Jul 9, 2013 · 5 comments
Closed

Complete pytest #257

dbrgn opened this issue Jul 9, 2013 · 5 comments
Labels

Comments

@dbrgn
Copy link
Collaborator

dbrgn commented Jul 9, 2013

Completion in pytest does not work.

In [1]: import jedi

In [2]: jedi._quick_complete('import pytest; pytest.')
Out[2]: 
[<Completion: cmdline>,
 <Completion: main>,
 <Completion: pytest>,
 <Completion: UsageError>,
 <Completion: _preloadplugins>,
 <Completion: __all__>,
 <Completion: __version__>]

There are many attributes missing:

In [3]: import pytest

In [4]: pytest.
pytest.Class            pytest.Instance         pytest.cmdline          pytest.fixture          pytest.set_trace
pytest.Collector        pytest.Item             pytest.collect          pytest.importorskip     pytest.skip
pytest.File             pytest.Module           pytest.deprecated_call  pytest.main             pytest.xfail
pytest.Function         pytest.Session          pytest.exit             pytest.mark             
pytest.Generator        pytest.UsageError       pytest.fail             pytest.raises           
@dbrgn
Copy link
Collaborator Author

dbrgn commented Jul 9, 2013

The reason for this is that pytest uses some code to populate the namespace, including all plugins.

if __name__ == '__main__': # if run as a script or by 'python -m pytest'                            
    # we trigger the below "else" condition by the following import                                 
    import pytest                                                                                   
    raise SystemExit(pytest.main())                                                                 
else:                                                                                               
    # we are simply imported                                                                        
    from _pytest.core import main, UsageError, _preloadplugins                                                            
    from _pytest import core as cmdline                                                                
    from _pytest import __version__                                                                    
    _preloadplugins() # to populate pytest.* namespace so help(pytest) works                           

_preloadplugins looks like this:

def _preloadplugins():                                                                                                    
    _preinit.append(PluginManager(load=True))                                                          

@davidhalter
Copy link
Owner

pytest uses __import__, which is not supported by Jedi. And btw: I'm pretty sure that Jedi will never support such a complicated import procedure. I don't know why they have it, but I think it's a stupid idea (also the whole having two namespaces pytest and _pytest). I'm closing, since I don't see a possibility to support this (I needed a few minutes to understand it myself, which is obviously a bad sign).

@blueyed
Copy link
Contributor

blueyed commented Oct 14, 2016

@davidhalter

pytest uses __import__, which is not supported by Jedi.

Is that still the case, or has there been progress in that regard?

I'm pretty sure that Jedi will never support such a complicated import procedure. I don't know why they have it

AFAIK this is done for the plugin system, which is also used internally.
I could imagine to improve it so that at least the builtin plugins would be completed.

Is there a way to whitelist e.g. this specific module to allow for code execution to discover imports? (assuming that this is the main issue here)

What about some callback that could be provided to help Jedi here?

@davidhalter
Copy link
Owner

I'm currently on holidays (have been for 2 weeks already), might still take another week until I answer.

@davidhalter
Copy link
Owner

pytest uses __import__, which is not supported by Jedi.

Is that still the case, or has there been progress in that regard?

Yes, that is still the case. However the big difference is that the import logic in Jedi is very similar to Python's. This means that implementing __import__ would probably not be a lot of work.

I'm not sure if this would really help you, though (for this problem).

I could imagine to improve it so that at least the builtin plugins would be completed.

What would be your plan?

Is there a way to whitelist e.g. this specific module to allow for code execution to discover imports? (assuming that this is the main issue here)

There's currently no whitelist. Well, maybe there is. But I'm not sure if setings.auto_import_modules is the right point to start.

What about some callback that could be provided to help Jedi here?

Well, tell me what you need and we talk :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants