How to use _capture_globals method in Slash

Best Python code snippet using slash

traceback_utils.py

Source:traceback_utils.py Github

copy

Full Screen

...108 if repr_blacklisted_types is None:109 repr_blacklisted_types = tuple(config.root.log.repr_blacklisted_types)110 self._repr_blacklisted_types = repr_blacklisted_types111 self._locals = self._capture_locals(frame)112 self._globals = self._capture_globals(frame)113 self.code_line = linecache.getline(self.filename, self.lineno).rstrip()114 self.code_string = "".join(115 linecache.getline(self.filename, lineno)116 for lineno in range(frame.f_code.co_firstlineno, self.lineno + 1)) or None117 if context.test is not None:118 test_function = get_underlying_func(context.test.get_test_function())119 self._is_in_test_code = frame.f_code is test_function.__code__120 else:121 self._is_in_test_code = False122 @property123 @deprecated(since='1.5.0')124 def locals(self):125 return self._locals126 @property127 @deprecated(since='1.5.0')128 def globals(self):129 return self._globals130 def forget_python_frame(self):131 self.python_frame = None132 def is_in_test_code(self):133 return self._is_in_test_code134 def to_dict(self):135 serialized = {}136 for attr in ['filename', 'lineno', 'func_name', 'code_line', 'code_string']:137 serialized[attr] = getattr(self, attr)138 serialized['globals'] = self._globals139 serialized['locals'] = self._locals140 serialized['is_in_test_code'] = self._is_in_test_code141 return serialized142 def _capture_globals(self, frame):143 used_globals = set(frame.f_code.co_names)144 return dict((global_name, {"value": _safe_repr(value, self._repr_blacklisted_types)})145 for global_name, value in frame.f_globals.items()146 if global_name in used_globals and self._is_global_included(value))147 def _is_global_included(self, g):148 if isinstance(g, (types.FunctionType, types.MethodType, types.ModuleType, type)):149 return False150 return True151 def _capture_locals(self, frame):152 return dict((local_name, {"value": _safe_repr(local_value, self._repr_blacklisted_types)})153 for key, value in frame.f_locals.items()154 if "@" not in key155 for local_name, local_value in self._unwrap_local(key, value, self._repr_blacklisted_types))156 def _unwrap_local(self, local_name, local_value, repr_blacklisted_types):...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...67 returned = traceback.to_list()68 for frame, distilled_dict in zip(traceback.frames, returned):69 if 'locals' not in distilled_dict and hasattr(frame, 'python_frame'): # Slash 1.5.x deprecates the `locals` and `globals` attributes70 distilled_dict['locals'] = _capture_locals(frame.python_frame, repr_blacklisted_types)71 distilled_dict['globals'] = _capture_globals(frame.python_frame, repr_blacklisted_types)72 return returned73def _capture_locals(frame, repr_blacklisted_types):74 if frame is None:75 return None76 return {local_name: {"value": _safe_repr(local_value, repr_blacklisted_types)}77 for key, value in frame.f_locals.items()78 if "@" not in key79 for local_name, local_value in _unwrap_object_variable(key, value)}80def _unwrap_object_variable(var_name, var_value):81 yield var_name, var_value82 if var_name != 'self':83 return84 for attr, value in _iter_distilled_object_attributes(var_value):85 yield f'self.{attr}', value86def _iter_distilled_object_attributes(obj):87 try:88 obj_dict = getattr(obj, '__dict__', {})89 except Exception: # pylint: disable=broad-except90 obj_dict = {}91 for attr in obj_dict:92 if attr.startswith('__') and attr.endswith('__'):93 continue94 try:95 value = getattr(obj, attr)96 except Exception: # pylint: disable=broad-except97 continue98 if isinstance(value, _FILTERED_MEMBER_TYPES):99 continue100 yield attr, value101def _capture_globals(frame, repr_blacklisted_types):102 if frame is None:103 return None104 used_globals = set(frame.f_code.co_names)105 return dict((global_name, {"value": _safe_repr(value, repr_blacklisted_types)})106 for global_name, value in frame.f_globals.items()107 if global_name in used_globals and _is_global_included(value))108def _is_global_included(global_variable):109 if isinstance(global_variable, (types.FunctionType, types.MethodType, types.ModuleType, type)):110 return False111 return True112def _splice_lines(lines, pivot, margin):113 if pivot >= len(lines):114 return ([], "<missing line>", [])115 return (lines[max(0, pivot-margin):pivot],...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful