diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/unittest/mock.py | 5 | ||||
-rw-r--r-- | Lib/unittest/test/testmock/testmock.py | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py index 4db1bac..d43ea9e 100644 --- a/Lib/unittest/mock.py +++ b/Lib/unittest/mock.py @@ -632,8 +632,9 @@ class NonCallableMock(Base): raise AttributeError(name) if not self._mock_unsafe: if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')): - raise AttributeError("Attributes cannot start with 'assert' " - "or its misspellings") + raise AttributeError( + f"{name} is not a valid assertion. Use a spec " + f"for the mock if {name} is meant to be an attribute.") 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 dfcf1ef..016905c 100644 --- a/Lib/unittest/test/testmock/testmock.py +++ b/Lib/unittest/test/testmock/testmock.py @@ -1598,7 +1598,7 @@ class MockTest(unittest.TestCase): #Issue21238 def test_mock_unsafe(self): m = Mock() - msg = "Attributes cannot start with 'assert' or its misspellings" + msg = "is not a valid assertion. Use a spec for the mock" with self.assertRaisesRegex(AttributeError, msg): m.assert_foo_call() with self.assertRaisesRegex(AttributeError, msg): |