bpo-24758: Improve the error msg for unittest.mock.Mock()'s unsafe mode
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 351aba5d44d7f4..a33a6208d6b584 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -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:
diff --git a/Lib/unittest/test/testmock/testmock.py b/Lib/unittest/test/testmock/testmock.py
index 5f917dd20f1dde..b20b8e20e7e6fd 100644
--- a/Lib/unittest/test/testmock/testmock.py
+++ b/Lib/unittest/test/testmock/testmock.py
@@ -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()



<!-- issue-number: [bpo-24758](https://bugs.python.org/issue24758) -->
https://bugs.python.org/issue24758
<!-- /issue-number -->
