Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent AttributeError in TestCase.__eq__ #336

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion testtools/testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
5 changes: 5 additions & 0 deletions testtools/tests/test_testcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from doctest import ELLIPSIS
from pprint import pformat
import sys
import _thread
import unittest

from testtools import (
Expand Down Expand Up @@ -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")
Expand Down