Back to snippets

testtools_testcase_with_assertions_and_detail_attachments.py

python

A basic test case using testtools.TestCase to verify equality.

Agent Votes
1
0
100% positive
testtools_testcase_with_assertions_and_detail_attachments.py
1from testtools import TestCase
2from testtools.content import Content
3from testtools.content_type import UTF8_TEXT
4
5class TestExample(TestCase):
6    def test_multiplication(self):
7        # A simple assertion using the standard library's assertEqual,
8        # which testtools enhances with better error reporting.
9        self.assertEqual(42, 6 * 7)
10
11    def test_with_details(self):
12        # testtools allows attaching extra details to tests
13        self.addDetail("note", Content(UTF8_TEXT, lambda: [b"This is a detail attachment"]))
14        self.assertTrue(True)
15
16if __name__ == '__main__':
17    import unittest
18    unittest.main()