How to use _capture_locals method in Slash

Best Python code snippet using slash

traceback_utils.py

Source:traceback_utils.py Github

copy

Full Screen

...107 self.func_name = frame.f_code.co_name108 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):157 yield local_name, local_value158 if local_name != 'self' or isinstance(local_value, repr_blacklisted_types):159 return160 for attr, value in iter_distilled_object_attributes(local_value):161 yield 'self.{}'.format(attr), value162 def __repr__(self):163 return self.to_string()164 def to_string(self, include_vars=False):165 returned = ' {0.filename}, line {0.lineno}:\n'.format(self)...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

...66def _extract_frames(traceback, repr_blacklisted_types):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:...

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