Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ def __getattr__(self, name):
raise AttributeError(name)
if not self._mock_unsafe:
if name.startswith(('assert', 'assret')):
raise AttributeError(name)
raise AttributeError("Attributes cannot start with 'assert' "
"or 'assret'")

result = self._mock_children.get(name)
if result is _deleted:
Expand Down
5 changes: 3 additions & 2 deletions Lib/unittest/test/testmock/testmock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1453,9 +1453,10 @@ def static_method(): pass
#Issue21238
def test_mock_unsafe(self):
m = Mock()
with self.assertRaises(AttributeError):
msg = "Attributes cannot start with 'assert' or 'assret'"
with self.assertRaisesRegex(AttributeError, msg):
m.assert_foo_call()
with self.assertRaises(AttributeError):
with self.assertRaisesRegex(AttributeError, msg):
m.assret_foo_call()
m = Mock(unsafe=True)
m.assert_foo_call()
Expand Down