From 709d5e3f2cc11face6de738d80d15bfb47aadaed Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Tue, 25 Jan 2011 20:47:34 +0000 Subject: [PATCH] Improve the "not in" assertion output This cleans up the generic diff and tailors the output more to this specific assertion (based on feedback from hpk). --- _pytest/assertion.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/_pytest/assertion.py b/_pytest/assertion.py index 8f09e6661..b142790a6 100644 --- a/_pytest/assertion.py +++ b/_pytest/assertion.py @@ -165,4 +165,15 @@ def _notin_text(term, text): head = text[:index] tail = text[index+len(term):] correct_text = head + tail - return _diff_text(correct_text, text) + diff = _diff_text(correct_text, text) + newdiff = ['%s is contained here:' % py.io.saferepr(term, maxsize=42)] + for line in diff: + if line.startswith('Skipping'): + continue + if line.startswith('- '): + continue + if line.startswith('+ '): + newdiff.append(' ' + line[2:]) + else: + newdiff.append(line) + return newdiff