def discover_inner(locator, suites=None): suites = suites or [] if isinstance(locator, basestring): import_error = None try: test_module = __import__(locator) except (ValueError, ImportError), e: import_error = e _log.info('discover_inner: Failed to import %s: %s' % (locator, e)) if os.path.isfile(locator) or os.path.isfile(locator+'.py'): here = os.path.abspath(os.path.curdir) + os.path.sep new_loc = os.path.abspath(locator) if not new_loc.startswith(here): raise DiscoveryError('Can only load modules by path within the current directory') new_loc = new_loc[len(here):] new_loc = new_loc.rsplit('.py',1)[0] #allows for .pyc and .pyo as well new_loc = new_loc.replace(os.sep,'.') try: test_module = __import__(new_loc) locator = new_loc del new_loc except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) else: try: test_module = __import__('.'.join(locator.split('.')[:-1])) except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) except Exception: raise DiscoveryError("Got unknown error when trying to import %s:\n\n%s" % ( locator, ''.join(traceback.format_exception(*sys.exc_info())) ))
def discover_inner(locator, suites=None): suites = suites or [] if isinstance(locator, basestring): import_error = None try: test_module = __import__(locator) except (ValueError, ImportError), e: import_error = e _log.info('discover_inner: Failed to import %s: %s' % (locator, e)) if os.path.isfile(locator) or os.path.isfile(locator+'.py'): new_loc = os.path.relpath(os.path.normpath(locator)) new_loc = new_loc.rsplit('.py',1)[0] #allows for .pyc and .pyo as well new_loc = new_loc.replace(os.sep,'.') try: test_module = __import__(new_loc) locator = new_loc del new_loc except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) else: try: test_module = __import__('.'.join(locator.split('.')[:-1])) except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) for part in locator.split('.')[1:]: try: test_module = getattr(test_module, part) except AttributeError: message = "discovery(%s) failed: module %s has no attribute %r" % (locator, test_module, part) if import_error is not None: message += "; this is most likely due to earlier error %r" % (import_error,) raise DiscoveryError(message)
def discover_inner(locator, suites=None): suites = suites or [] if isinstance(locator, basestring): import_error = None try: test_module = __import__(locator) except (ValueError, ImportError), e: import_error = e _log.info('discover_inner: Failed to import %s: %s' % (locator, e)) if os.path.isfile(locator) or os.path.isfile(locator + '.py'): here = os.path.abspath(os.path.curdir) + os.path.sep new_loc = os.path.abspath(locator) if not new_loc.startswith(here): raise DiscoveryError( 'Can only load modules by path within the current directory' ) new_loc = new_loc[len(here):] new_loc = new_loc.rsplit( '.py', 1)[0] #allows for .pyc and .pyo as well new_loc = new_loc.replace(os.sep, '.') try: test_module = __import__(new_loc) locator = new_loc del new_loc except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) else: try: test_module = __import__('.'.join( locator.split('.')[:-1])) except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) for part in locator.split('.')[1:]: try: test_module = getattr(test_module, part) except AttributeError: message = "discovery(%s) failed: module %s has no attribute %r" % ( locator, test_module, part) if import_error is not None: message += "; this is most likely due to earlier error %r" % ( import_error, ) raise DiscoveryError(message)
def discover_inner(locator, suites=None): suites = suites or [] if isinstance(locator, basestring): import_error = None try: test_module = __import__(locator) except (ValueError, ImportError), e: import_error = e _log.info('discover_inner: Failed to import %s: %s' % (locator, e)) if os.path.isfile(locator) or os.path.isfile(locator + '.py'): here = os.path.abspath(os.path.curdir) + os.path.sep new_loc = os.path.abspath(locator) if not new_loc.startswith(here): raise DiscoveryError( 'Can only load modules by path within the current directory' ) new_loc = new_loc[len(here):] new_loc = new_loc.rsplit( '.py', 1)[0] #allows for .pyc and .pyo as well new_loc = new_loc.replace(os.sep, '.') try: test_module = __import__(new_loc) locator = new_loc del new_loc except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) else: try: test_module = __import__('.'.join( locator.split('.')[:-1])) except (ValueError, ImportError): raise DiscoveryError("Failed to find module %s" % locator) except Exception: raise DiscoveryError( "Got unknown error when trying to import %s:\n\n%s" % (locator, ''.join( traceback.format_exception(*sys.exc_info()))))
def discover_inner(locator, suites=None): suites = suites or [] if isinstance(locator, basestring): import_error = None try: test_module = __import__(locator) except ImportError, e: import_error = e _log.info('discover_inner: Failed to import %s: %s' % (locator, e)) try: test_module = __import__('.'.join(locator.split('.')[:-1])) except ValueError: raise DiscoveryError("Failed to find module %s" % locator) for part in locator.split('.')[1:]: try: test_module = getattr(test_module, part) except AttributeError, exc: message = "discovery(%s) failed: module %s has no attribute %r" % (locator, test_module, part) if import_error is not None: message += "; this is most likely due to earlier error %r" % (import_error,) raise DiscoveryError(message)