For the actual content of details, testtools uses its own MIME-based Content object. This allows you to attach any information that you could possibly conceive of to a test, and allows testtools to use or serialize that information.
The basic testtools.content.Content object is constructed from a testtools.content.ContentType and a nullary callable that must return an iterator of chunks of bytes that the content is made from.
So, to make a Content object that is just a simple string of text, you can do:
from testtools.content import Content from testtools.content_type import ContentType text = Content(ContentType('text', 'plain'), lambda: ["some text"])
Because adding small bits of text content is very common, there’s also a convenience method:
text = text_content("some text")
To make content out of an image stored on disk, you could do something like:
image = Content(ContentType('image', 'png'), lambda: open('foo.png').read())
Or you could use the convenience function:
image = content_from_file('foo.png', ContentType('image', 'png'))
The lambda helps make sure that the file is opened and the actual bytes read only when they are needed – by default, when the test is finished. This means that tests can construct and add Content objects freely without worrying too much about how they affect run time.