← Back to team overview

testtools-dev team mailing list archive

[Bug 804127] Re: assertThat(..., verbose=True) sometimes generates unprintable AssertionErrors

 

Well, yes, I agree we should avoid mangling down if we can.

I'm not clear on which bits of the interface you think are not clear. 
  * Mismatch.describe() has a poorly defined return type – is it bytes or is it text? 
  * Matcher objects must have a working __str__(), but I have to confess I don't know what that is supposed to return in code that works on both Python 2 & 3.
  * assertThat also calls str() on the matchee, which can be anything.
  * These three "strings" are all whacked together and passed to self.fail(), which is in turn passed to AssertionError.

Things I'm happy to change or clarify:
  * Give Mismatch.describe() a clear return type. Pick one of bytes or text.  I think the latter makes sense.
  * I don't really care about Matcher.__str__. Bug 686807 shows that it's not great as is.
  * We can do whatever we want to the matchee to get a human-readable thing out of it.
  * We can raise our own exception. But if we do, it should be a subclass of AssertionError.

Whatever we do, we need to be really conscious of maintaining
compatibility with Matchers outside of testtools.

-- 
You received this bug notification because you are a member of testtools
developers, which is subscribed to testtools.
https://bugs.launchpad.net/bugs/804127

Title:
  assertThat(..., verbose=True) sometimes generates unprintable
  AssertionErrors

Status in testtools:
  Triaged

Bug description:
  The assertThat method for use with matchers creates AssertionError
  instances that don't stringify on Python 2.4, 2.5, and some 2.6 minor
  versions when used with a non-ascii unicode argument. The
  testtools.testresults code has some robustness that means the failure
  is still printed, but other runners may break if the
  UnicodeEncodeError from trying to stringify the exception propagates.

  Instead of the expected output, these older Pythons get:

  Traceback (most recent call last):
    ...
      self.assertThat(u"\xa7", Equals(u"a"), verbose=True)
    File "C:\Python24\Lib\site-packages\testtools\testcase.py", line 351, in assertThat
      self.fail('Match failed. Matchee: "%s"\nMatcher: %s\nDifference: %s\n'
  AssertionError: <unprintable AssertionError object>

To manage notifications about this bug go to:
https://bugs.launchpad.net/testtools/+bug/804127/+subscriptions


References