Please allow Mismatches to add detail to the result

Bug #591327 reported by James Westby
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
testtools
Fix Released
Wishlist
James Westby

Bug Description

Hi,

addDetail is great!
Matchers are great!
If only I could use them together without extra code!

My proposal

  class Mismatch(object):
     details = []

  def assertThat(matchee, matcher):
     match = matcher.match(matchee)
     if match is not None:
         if getattr(match, details, None) is not None:
             map(self.addDetail, match.details)
         self.fail(....

See what I mean?

That way as an author of a library of Matchers I can provide useful
detail to users without having to put it in to the result of describe().

In particular when a problem is found within a HTML page I want to provide
the user with a compact error message, but still provide them the source of
the page for investigation if they like.

Thanks,

James

P.S. does testr have a nice way to view attachments from the last run?

Revision history for this message
Robert Collins (lifeless) wrote :

Regarding the PS: testr failing will show all the attachments for failures, its the default serialisation to show everything.

The proposal is broadly ok. A few tweaks:
 - a method please, not an attribute (allows lazy generation more obviously)
 - no need to guard against old Mismatch objects, change the base class, this is marked experimental in our docs.
 - perhaps a dict rather than tuples ?
 - also, given the TestCase may already have the names used, it will need to append -1 -2 etc to names that are already used. Or something like that.

+1 on the overall concept though - I likes.

Changed in testtools:
status: New → Triaged
importance: Undecided → Wishlist
James Westby (james-w)
Changed in testtools:
status: Triaged → In Progress
assignee: nobody → James Westby (james-w)
Changed in testtools:
status: In Progress → Fix Released
milestone: none → next
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.