Best Python code snippet using nose2
util.py
Source:util.py
...91 for part in parts:92 try:93 parent, obj = obj, getattr(obj, part)94 except AttributeError as e:95 if is_package_or_module(obj) and import_error:96 # Re-raise the import error which got us here, since97 # it probably better describes the issue.98 _raise_custom_attribute_error(obj, part, e, import_error)99 else:100 raise101 return parent, obj102def _raise_custom_attribute_error(obj, attr, attr_error_exc, prev_exc):103 if sys.version_info >= (3, 0):104 six.raise_from(attr_error_exc, prev_exc[1])105 # for python 2, do exception chaining manually106 raise AttributeError(107 "'%s' has not attribute '%s'\n\nMaybe caused by\n\n%s" % (108 obj, attr, '\n'.join(traceback.format_exception(*prev_exc))))109def is_package_or_module(obj):110 if hasattr(obj, '__path__') or isinstance(obj, types.ModuleType):111 return True112 return False113def try_import_module_from_name(splitted_name):114 """115 Try to find the longest importable from the ``splitted_name``, and return116 the corresponding module, as well as the potential ``ImportError``117 exception that occurs when trying to import a longer name.118 For instance, if ``splitted_name`` is ['a', 'b', 'c'] but only ``a.b`` is119 importable, this function:120 121 1. tries to import ``a.b.c`` and fails122 2. tries to import ``a.b`` and succeeds123 3. return ``a.b`` and the exception that occured at step 1....
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!