[py-dev] Re: Error with py.test and scipy ...

Valentino Volonghi aka Dialtone dialtone at divmod.com
Fri Apr 8 01:35:11 CEST 2005


holger krekel wrote:

>I would be surprised if my brand-new hack breaks yours (because that
>is exactly what it is trying to avoid) but i've learned that "import" 
>makes the impossible possible and vice versa. 
>
>cheers, 
>  
>
It was a quick fix in my case :).

It shouldn't be hard to figure out a common failing pattern in import 
magic. for example:
nevow was failing because of namedAny that imports a module from a 
string representing the entire path in PYTHONPATH.

from nevow import util
In [6]:util.namedAny('nevow.flat.ten')
Out[6]:<module 'nevow.flat.ten' from 
'/Volumes/dati/Sviluppo/Nevow/nevow/flat/ten.pyc'>

namedAny is this one:

def namedAny(name):
    """Get a fully named package, module, module-global object, or 
attribute.
    """
    names = name.split('.')
    topLevelPackage = None
    moduleNames = names[:]
    while not topLevelPackage:
        try:
            trialname = '.'.join(moduleNames)
            topLevelPackage = __import__(trialname)
        except ImportError:
            # if the ImportError happened in the module being imported,
            # this is a failure that should be handed to our caller.
            # count stack frames to tell the difference.

            # string-matching is another technique, but I think it could be
            # fooled in some funny cases
            #if sys.exc_info()[1] != "cannot import name %s" % trialname:
            #    raise
            import traceback
            if len(traceback.extract_tb(sys.exc_info()[2])) > 1:
                raise
            moduleNames.pop()
   
    obj = topLevelPackage
    for n in names[1:]:
        obj = getattr(obj, n)
       
    return obj

But I can't remember exactly the failure. The ML is here to help 
(something about the PYTHONPATH anyway).

-- 
Valentino Volonghi aka Dialtone
Now Running MacOSX 10.3.8
Blog: http://vvolonghi.blogspot.com
http://weever.berlios.de




More information about the Pytest-dev mailing list