From: david-sarah Date: Wed, 12 May 2010 06:07:54 +0000 (-0700) Subject: Change shouldFail to avoid Unicode errors when converting Failure to str X-Git-Tag: trac-4400~49 X-Git-Url: https://git.rkrishnan.org/?a=commitdiff_plain;h=e706f043f03cfc8876b107bc8c9571fc0af15cc4;p=tahoe-lafs%2Ftahoe-lafs.git Change shouldFail to avoid Unicode errors when converting Failure to str --- diff --git a/src/allmydata/test/common.py b/src/allmydata/test/common.py index 8f790130..9f37073a 100644 --- a/src/allmydata/test/common.py +++ b/src/allmydata/test/common.py @@ -1090,8 +1090,8 @@ class ShouldFailMixin: error message, if any, because Deferred chains frequently make it difficult to tell which assertion was tripped. - The substring= argument, if not None, must appear inside the - stringified Failure, or the test will fail. + The substring= argument, if not None, must appear in the 'repr' + of the message wrapped by this Failure, or the test will fail. """ assert substring is None or isinstance(substring, str) @@ -1100,9 +1100,10 @@ class ShouldFailMixin: if isinstance(res, failure.Failure): res.trap(expected_failure) if substring: - self.failUnless(substring in str(res), + message = repr(res.value.args[0]) + self.failUnless(substring in message, "substring '%s' not in '%s'" - % (substring, str(res))) + % (substring, message)) else: self.fail("%s was supposed to raise %s, not get '%s'" % (which, expected_failure, res))