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

Function saferepr

src/_pytest/_io/saferepr.py:124–136  ·  view source on GitHub ↗

Return a size-limited safe repr-string for the given object. Failing __repr__ functions of user instances will be represented with a short exception info and 'saferepr' generally takes care to never raise exceptions itself. This function is a wrapper around the Repr/reprlib functio

(
    obj: object, maxsize: int | None = DEFAULT_REPR_MAX_SIZE, use_ascii: bool = False
)

Source from the content-addressed store, hash-verified

122
123
124def saferepr(
125 obj: object, maxsize: int | None = DEFAULT_REPR_MAX_SIZE, use_ascii: bool = False
126) -> str:
127 """Return a size-limited safe repr-string for the given object.
128
129 Failing __repr__ functions of user instances will be represented
130 with a short exception info and 'saferepr' generally takes
131 care to never raise exceptions itself.
132
133 This function is a wrapper around the Repr/reprlib functionality of the
134 stdlib.
135 """
136 return SafeRepr(maxsize, use_ascii).repr(obj)
137
138
139def saferepr_unlimited(obj: object, use_ascii: bool = True) -> str:

Callers 15

__post_init__Method · 0.90
_show_fixture_actionFunction · 0.90
_safereprFunction · 0.90
_format_assertmsgFunction · 0.90
_compare_eq_sequenceFunction · 0.90
_compare_eq_mappingFunction · 0.90
_set_one_sided_diffFunction · 0.90
assertrepr_compareFunction · 0.90
_notin_textFunction · 0.90
reprMethod · 0.90

Calls 2

SafeReprClass · 0.85
reprMethod · 0.45

Tested by 13

__post_init__Method · 0.72
test_serializationFunction · 0.72
test_simple_reprFunction · 0.72
test_maxsizeFunction · 0.72
test_no_maxsizeFunction · 0.72
test_exceptionsFunction · 0.72
test_baseexceptionFunction · 0.72
test_buggy_builtin_reprFunction · 0.72
test_big_reprFunction · 0.72
test_repr_on_newstyleFunction · 0.72
test_unicodeFunction · 0.72