Best Python code snippet using avocado_python
stacktrace.py
Source:stacktrace.py
...46 if isinstance(logger, str):47 logger = logging.getLogger(logger)48 for line in message.splitlines():49 logger.error(line)50def analyze_unpickable_item(path_prefix, obj):51 """52 Recursive method to obtain unpickable objects along with location53 :param path_prefix: Path to this object54 :param obj: The sub-object under introspection55 :return: [($path_to_the_object, $value), ...]56 """57 _path_prefix = path_prefix58 try:59 if hasattr(obj, "items"):60 subitems = obj.items()61 path_prefix += "[%s]"62 elif isinstance(obj, list):63 subitems = enumerate(obj)64 path_prefix += "[%s]"65 elif hasattr(obj, "__iter__"):66 subitems = enumerate(obj.__iter__())67 path_prefix += "<%s>"68 elif hasattr(obj, "__dict__"):69 subitems = obj.__dict__.items()70 path_prefix += ".%s"71 else:72 return [(path_prefix, obj)]73 except Exception: # pylint: disable=W070374 return [(path_prefix, obj)]75 unpickables = []76 for key, value in subitems:77 try:78 pickle.dumps(value)79 except pickle.PickleError:80 ret = analyze_unpickable_item(path_prefix % key, value)81 if ret:82 unpickables.extend(ret)83 if not unpickables:84 return [(_path_prefix, obj)]85 return unpickables86def str_unpickable_object(obj):87 """88 Return human readable string identifying the unpickable objects89 :param obj: The object for analysis90 :raise ValueError: In case the object is pickable91 """92 try:93 pickle.dumps(obj)94 except pickle.PickleError:95 pass96 else:97 raise ValueError("This object is pickable:\n%s" % pformat(obj))98 unpickables = analyze_unpickable_item("this", obj)99 return ("Unpickable object in:\n %s\nItems causing troubles:\n "100 % "\n ".join(pformat(obj).splitlines()) +...
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!!