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

Function safeformat

src/_pytest/_io/saferepr.py:108–117  ·  view source on GitHub ↗

Return a pretty printed string for the given object. Failing __repr__ functions of user instances will be represented with a short exception info.

(obj: object)

Source from the content-addressed store, hash-verified

106
107
108def safeformat(obj: object) -> str:
109 """Return a pretty printed string for the given object.
110
111 Failing __repr__ functions of user instances will be represented
112 with a short exception info.
113 """
114 try:
115 return pprint.pformat(obj)
116 except Exception as exc:
117 return _format_repr_exception(exc, obj)
118
119
120# Maximum size of overall repr of objects to display during assertion errors.

Callers 1

repr_localsMethod · 0.90

Calls 2

_format_repr_exceptionFunction · 0.85
pformatMethod · 0.80

Tested by

no test coverage detected