diff --git a/src/_pytest/_io/saferepr.py b/src/_pytest/_io/saferepr.py index 49f747dc2..520d6c4d1 100644 --- a/src/_pytest/_io/saferepr.py +++ b/src/_pytest/_io/saferepr.py @@ -64,13 +64,7 @@ class SafeRepr(reprlib.Repr): # for bound methods, skip redundant information s = x.__name__ else: - # if none of the mro classes have implemented __repr__ - # show class name - mro_classes = x.__class__.mro()[:-1] - if not any("__repr__" in cls.__dict__ for cls in mro_classes): - s = x.__class__.__name__ - else: - s = super().repr(x) + s = super().repr(x) except (KeyboardInterrupt, SystemExit): raise diff --git a/testing/io/test_saferepr.py b/testing/io/test_saferepr.py index 075d40cdf..a69f72544 100644 --- a/testing/io/test_saferepr.py +++ b/testing/io/test_saferepr.py @@ -192,3 +192,28 @@ def test_saferepr_unlimited_exc(): assert saferepr_unlimited(A()).startswith( "<[ValueError(42) raised in repr()] A object at 0x" ) + + +class TestSafereprUnbounded: + class Help: + def __init__(self, i): + self.i = i + + def bound_method(self): + return self.i + + def test_saferepr_bound_method(self): + """saferepr() of a bound method should show only the method name""" + assert saferepr(self.Help(10).bound_method) == "bound_method" + + def test_saferepr_unbounded(self): + """saferepr() of an unbound method should still show the full information""" + obj = self.Help(10) + assert ( + saferepr(obj) + == f"" + ) + assert ( + saferepr(self.Help) + == f"" + )