diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index 5d91aeb..fb6eddc 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -214,6 +214,9 @@ class Tracer: self.target_codes = set() self.target_frames = set() self.thread_local = threading.local() + if len(custom_repr) == 2 and not all(isinstance(x, + pycompat.collections_abc.Iterable) for x in custom_repr): + custom_repr = (custom_repr,) self.custom_repr = custom_repr def __call__(self, function): diff --git a/tests/test_pysnooper.py b/tests/test_pysnooper.py index 0b93845..930dd5d 100644 --- a/tests/test_pysnooper.py +++ b/tests/test_pysnooper.py @@ -1174,6 +1174,30 @@ def test_custom_repr(): ) ) +def test_custom_repr_single(): + string_io = io.StringIO() + + @pysnooper.snoop(string_io, custom_repr=(list, lambda l: 'foofoo!')) + def sum_to_x(x): + l = list(range(x)) + return 7 + + result = sum_to_x(10000) + + output = string_io.getvalue() + assert_output( + output, + ( + VariableEntry('x', '10000'), + CallEntry(), + LineEntry(), + VariableEntry('l', 'foofoo!'), + LineEntry(), + ReturnEntry(), + ReturnValueEntry('7'), + ) + ) + def test_disable(): string_io = io.StringIO()