summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/mock.py
diff options
context:
space:
mode:
authorvabr-g <vabr@google.com>2020-12-10 18:35:28 (GMT)
committerGitHub <noreply@github.com>2020-12-10 18:35:28 (GMT)
commit9fc571359af9320fddbe4aa2710a767f168c1707 (patch)
tree62ac7bab3185ac676c211eb4d5b530c65f46e052 /Lib/unittest/mock.py
parentb5c7b38f5ebbc84b5b80192db1743d3e1cdcf4c5 (diff)
downloadcpython-9fc571359af9320fddbe4aa2710a767f168c1707.zip
cpython-9fc571359af9320fddbe4aa2710a767f168c1707.tar.gz
cpython-9fc571359af9320fddbe4aa2710a767f168c1707.tar.bz2
bpo-41877: Improve docs for assert misspellings check in mock (GH-23729)
This is a follow-up to https://github.com/python/cpython/commit/4662fa9bfe4a849fe87bfb321d8ef0956c89a772. That original commit expanded guards against misspelling assertions on mocks. This follow-up updates the documentation and improves the error message by pointing out the potential cause and solution. Automerge-Triggered-By: GH:gpshead
Diffstat (limited to 'Lib/unittest/mock.py')
-rw-r--r--Lib/unittest/mock.py5
1 files changed, 3 insertions, 2 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: