diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index 884f0a21e..23af4d0bb 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -99,5 +99,5 @@ class AlwaysDispatchingPrettyPrinter(pprint.PrettyPrinter): def _pformat_dispatch(object, indent=1, width=80, depth=None, *, compact=False): return AlwaysDispatchingPrettyPrinter( - indent=1, width=80, depth=None, compact=False + indent=indent, width=width, depth=depth, compact=compact ).pformat(object) diff --git a/testing/io/test_saferepr.py b/testing/io/test_saferepr.py index e24d9b470..06084202e 100644 --- a/testing/io/test_saferepr.py +++ b/testing/io/test_saferepr.py @@ -1,4 +1,5 @@ import pytest +from _pytest._io.saferepr import _pformat_dispatch from _pytest._io.saferepr import saferepr @@ -147,3 +148,9 @@ def test_unicode(): val = "£€" reprval = "'£€'" assert saferepr(val) == reprval + + +def test_pformat_dispatch(): + assert _pformat_dispatch("a") == "'a'" + assert _pformat_dispatch("a" * 10, width=5) == "'aaaaaaaaaa'" + assert _pformat_dispatch("foo bar", width=5) == "('foo '\n 'bar')"