Using addDetail() is fiddly for simple cases

Bug #922035 reported by Gavin Panella
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
testtools
Triaged
Wishlist
Unassigned

Bug Description

I want to be able to write, for example:

    with ExpectedException(Exception, "It dun broke"):
        return_value = yield session.call('double_fail')
        self.addDetail("return_value", return_value)

but instead I have to write:

    from testtools.content import text_content
    with ExpectedException(Exception, "It dun broke"):
        return_value = yield session.call('double_fail')
        self.addDetail("return_value", text_content(repr(return_value)))

or:

    from testtools.content import Content
    from testtools.content_type import UTF8_TEXT
    with ExpectedException(Exception, "It dun broke"):
        return_value = yield session.call('double_fail')
        self.addDetail(
            "return_value", Content(
                UTF8_TEXT, lambda: [repr(return_value)]))

It would make my life better if addDetail() did something sensible
with non-Content objects.

For example something as simple the following might be reasonable:

    def addDetail(self, name, content_object):
        if not isinstance(content_object, Content):
            content_object = text_content(repr(content_object))
        ...

Tags: details
Revision history for this message
Jonathan Lange (jml) wrote :

I think something like this is a good idea, and that attaching a repr of an object as text content is a sensible default.

Would probably prefer expressing this with an alternative parameter or a different function name, e.g.

  self.addDetail("return_value", None, return_value)

(can't think of a good keyword arg name right now). Or:

  self.attachObject("return_value", return_value)

Am not overly enamoured of that name either.

Changed in testtools:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Jonathan Lange (jml) wrote :

Fixing bug 849843 would make this a bit easier.

tags: added: details
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.