fix and test a unbound local in _diff_text of the assertion plugin
--HG-- branch : trunk
This commit is contained in:
parent
6b0db18eca
commit
09a9ce1da1
|
@ -75,8 +75,12 @@ def pytest_assertrepr_compare(op, left, right):
|
||||||
except py.builtin._sysex:
|
except py.builtin._sysex:
|
||||||
raise
|
raise
|
||||||
except:
|
except:
|
||||||
|
excinfo = py.code.ExceptionInfo()
|
||||||
explanation = ['(pytest_assertion plugin: representation of '
|
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:
|
if not explanation:
|
||||||
return None
|
return None
|
||||||
|
@ -95,6 +99,7 @@ def _diff_text(left, right):
|
||||||
identical to keep the diff minimal.
|
identical to keep the diff minimal.
|
||||||
"""
|
"""
|
||||||
explanation = []
|
explanation = []
|
||||||
|
i = 0 # just in case left or right has zero length
|
||||||
for i in range(min(len(left), len(right))):
|
for i in range(min(len(left), len(right))):
|
||||||
if left[i] != right[i]:
|
if left[i] != right[i]:
|
||||||
break
|
break
|
||||||
|
|
|
@ -103,6 +103,17 @@ class TestAssert_reprcompare:
|
||||||
expl = callequal({}, {'1': A()})
|
expl = callequal({}, {'1': A()})
|
||||||
assert 'faulty' in "".join(expl)
|
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
|
@needsnewassert
|
||||||
def test_pytest_assertrepr_compare_integration(testdir):
|
def test_pytest_assertrepr_compare_integration(testdir):
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
|
|
Loading…
Reference in New Issue