Commits

Ronny Pfannschmidt committed b2eefb2

fix and test a unbound local in _diff_text of the assertion plugin

Comments (0)

Files changed (2)

py/_plugin/pytest_assertion.py

     except py.builtin._sysex:
         raise
     except:
+        excinfo = py.code.ExceptionInfo()
         explanation = ['(pytest_assertion plugin: representation of '
-            'details failed. Probably an object has a faulty __repr__.)']
+            'details failed. Probably an object has a faulty __repr__.)',
+            str(excinfo)
+            ]
+
 
     if not explanation:
         return None
     identical to keep the diff minimal.
     """
     explanation = []
+    i = 0 # just in case left or right has zero length
     for i in range(min(len(left), len(right))):
         if left[i] != right[i]:
             break

testing/plugin/test_pytest_assertion.py

         expl = callequal({}, {'1': A()})
         assert 'faulty' in "".join(expl)
 
+    def test_one_repr_empty(self):
+        """
+        the faulty empty string repr did trigger
+        a unbound local error in _diff_text
+        """
+        class A(str):
+            def __repr__(self):
+                return ''
+        expl = callequal(A(), '')
+        assert not expl
+
 @needsnewassert
 def test_pytest_assertrepr_compare_integration(testdir):
     testdir.makepyfile("""