summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2022-11-06 12:36:29 +0000
committerGitHub <noreply@github.com>2022-11-06 12:36:29 +0000
commitd602d9a2532fa952647f635a2e97fe3de3cec49b (patch)
treedb4542e962ae13037a14bed1694495ea103c8a5b
parent58d5c3f9b91f572e1fa174f5472e3d0a92f948c3 (diff)
parent6286dbe3de4ab2ddb6ce9ba28cf959a8959423ed (diff)
downloadtesttools-d602d9a2532fa952647f635a2e97fe3de3cec49b.tar.gz
Merge pull request #336 from tipabu/eq-attribute-error
Prevent AttributeError in TestCase.__eq__
-rw-r--r--testtools/testcase.py2
-rw-r--r--testtools/tests/test_testcase.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/testtools/testcase.py b/testtools/testcase.py
index f3bd510..5bbff25 100644
--- a/testtools/testcase.py
+++ b/testtools/testcase.py
@@ -273,7 +273,7 @@ class TestCase(unittest.TestCase):
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 c2766ff..fa38d44 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 @@ class TestPlaceHolder(TestCase):
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")