Skip to content

Commit 3fa9e2e

Browse files
author
Roscoe A. Bartlett
committed
Show diff error in test failure exception
With Python 2.6, the unittest.TestCase.assertEqual() function (and all the other assert functions), take an optional 'msg' argument. With this, I can show the grep failure message right in the test failure exception. This just makes it much easier to see the details of the failures.
1 parent 98ccf70 commit 3fa9e2e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

test/ci_support/CheckinTest_UnitTests.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ def assertGrepFileForRegexStrList(testObject, testName, fileName, regexStrList,
8080
for regexToFind in regexStrList.strip().split('\n'):
8181
if regexToFind == "": continue
8282
foundRegex = getCmndOutput("grep '"+regexToFind+"' "+fileName, True, False)
83-
if verbose or not foundRegex:
84-
print "\n"+testName+": In '"+fileName+"' look for regex '"+regexToFind+"' ...",
85-
print "'"+foundRegex+"'",
86-
if foundRegex: print ": PASSED"
87-
else: print ": FAILED"
88-
testObject.assertNotEqual(foundRegex, "")
83+
msg = "\n"+testName+": In '"+fileName+"' look for regex '"+regexToFind+"' ..." \
84+
+ "'"+foundRegex+"'"
85+
if foundRegex: msg += ": PASSED"
86+
else: msg += ": FAILED"
87+
if verbose:
88+
print msg
89+
testObject.assertNotEqual(foundRegex, "", msg)
8990

9091

9192
def assertNotGrepFileForRegexStrList(testObject, testName, fileName, regexStrList, verbose):

0 commit comments

Comments
 (0)