MCPcopy
hub / github.com/pytest-dev/pytest / repr_locals

Method repr_locals

src/_pytest/_code/code.py:1040–1066  ·  view source on GitHub ↗
(self, locals: Mapping[str, object])

Source from the content-addressed store, hash-verified

1038 return lines
1039
1040 def repr_locals(self, locals: Mapping[str, object]) -> ReprLocals | None:
1041 if self.showlocals:
1042 lines = []
1043 # Variables starting with `@` are helpers injected by assertion
1044 # rewriting, not user variables, so hide them.
1045 keys = [loc for loc in locals if loc[0] != "@"]
1046 keys.sort()
1047 for name in keys:
1048 value = locals[name]
1049 if name == "__builtins__":
1050 lines.append("__builtins__ = <builtins>")
1051 else:
1052 # This formatting could all be handled by the
1053 # _repr() function, which is only reprlib.Repr in
1054 # disguise, so is very configurable.
1055 if self.truncate_locals:
1056 str_repr = saferepr(value)
1057 else:
1058 str_repr = safeformat(value)
1059 # if len(str_repr) < 70 or not isinstance(value, (list, tuple, dict)):
1060 lines.append(f"{name:<10} = {str_repr}")
1061 # else:
1062 # self._line("%-10s =\\" % (name,))
1063 # # XXX
1064 # pprint.pprint(value, stream=self.excinfowriter)
1065 return ReprLocals(lines)
1066 return None
1067
1068 def repr_traceback_entry(
1069 self,

Calls 4

safereprFunction · 0.90
safeformatFunction · 0.90
ReprLocalsClass · 0.85
appendMethod · 0.80