diff --git a/testtools/testcase.py b/testtools/testcase.py index 012def36..f3bd510b 100644 --- a/testtools/testcase.py +++ b/testtools/testcase.py @@ -275,6 +275,8 @@ def __eq__(self, other): return False return self.__dict__ == other.__dict__ + __hash__ = unittest.TestCase.__hash__ + def __repr__(self): # We add id to the repr because it makes testing testtools easier. return f"<{self.id()} id=0x{id(self):0x}>" diff --git a/testtools/tests/test_testcase.py b/testtools/tests/test_testcase.py index 00cb60da..c2766ffd 100644 --- a/testtools/tests/test_testcase.py +++ b/testtools/tests/test_testcase.py @@ -86,6 +86,10 @@ def test_shortDescription_specified(self): test = PlaceHolder("test id", "description") self.assertEqual("description", test.shortDescription()) + def test_testcase_is_hashable(self): + test = hash(self) + self.assertEqual(unittest.TestCase.__hash__(self), test) + def test_repr_just_id(self): # repr(placeholder) shows you how the object was constructed. test = PlaceHolder("test id")