diff --git a/testtools/testcase.py b/testtools/testcase.py index f3bd510b..5bbff252 100644 --- a/testtools/testcase.py +++ b/testtools/testcase.py @@ -273,7 +273,7 @@ def __eq__(self, other): eq = getattr(unittest.TestCase, '__eq__', None) if eq is not None and not unittest.TestCase.__eq__(self, other): return False - return self.__dict__ == other.__dict__ + return self.__dict__ == getattr(other, '__dict__', None) __hash__ = unittest.TestCase.__hash__ diff --git a/testtools/tests/test_testcase.py b/testtools/tests/test_testcase.py index c2766ffd..fa38d445 100644 --- a/testtools/tests/test_testcase.py +++ b/testtools/tests/test_testcase.py @@ -5,6 +5,7 @@ from doctest import ELLIPSIS from pprint import pformat import sys +import _thread import unittest from testtools import ( @@ -90,6 +91,10 @@ def test_testcase_is_hashable(self): test = hash(self) self.assertEqual(unittest.TestCase.__hash__(self), test) + def test_testcase_equals_edgecase(self): + # Not all python objects have a __dict__ attribute + self.assertFalse(self == _thread.RLock()) + def test_repr_just_id(self): # repr(placeholder) shows you how the object was constructed. test = PlaceHolder("test id")