[IPython-dev] Running tests

Fernando Perez fperez.net@gmail....
Mon Jan 11 14:52:24 CST 2010


On Mon, Jan 11, 2010 at 12:27 PM, Fernando Perez <fperez.net@gmail.com> wrote:
>
> I've started using absolute imports because they will become default
> eventually, and they do provide some other benefits (see pep if
> curious).  For the most part they are innocuous, but this little
> glitch will need addressing, thanks.  Now tracked:
>
> https://bugs.launchpad.net/ipython/+bug/506112
>

Actually it looks like I'm going to need some help here.  I tried
changing the bottom to:


# Relative imports and running a module as a script collide.  For Python2.6,
# there's a fix:
if sys.version_info[:2] >= (2,6):
    if __name__ == "__main__" and __package__ is None:
       __package__ = "IPython.testing"
       main()
# For 2.5 unfortunately this just doesn't work.  Our iptest script provides an
# entry point though...
else:
    if __name__ == '__main__':
        main()

But trying to run it as a script, with or without -m, still fails:

uqbar[testing]> python -m iptest.py
Traceback (most recent call last):
  File "/usr/lib/python2.6/runpy.py", line 104, in _run_module_as_main
    loader, code, fname = _get_module_details(mod_name)
  File "/usr/lib/python2.6/runpy.py", line 79, in _get_module_details
    loader = get_loader(mod_name)
  File "/usr/lib/python2.6/pkgutil.py", line 456, in get_loader
    return find_loader(fullname)
  File "/usr/lib/python2.6/pkgutil.py", line 466, in find_loader
    for importer in iter_importers(fullname):
  File "/usr/lib/python2.6/pkgutil.py", line 422, in iter_importers
    __import__(pkg)
  File "iptest.py", line 39, in <module>
    from . import globalipapp
ValueError: Attempted relative import in non-package
uqbar[testing]> python  iptest.py
Traceback (most recent call last):
  File "iptest.py", line 39, in <module>
    from . import globalipapp
ValueError: Attempted relative import in non-package
uqbar[testing]>


I'm obviously missing something in the explanation of

http://www.python.org/dev/peps/pep-0366/

Can someone enlighten me?

Otherwise I'll just back off the absolute imports for that module, it
may not be worth the hassle for now (at least until we understand how
to do it right).

Thanks!

f


More information about the IPython-dev mailing list