gh-100739: Respect mock spec when checking for unsafe prefixes (GH-100740)

(cherry picked from commit 7f1eefc6f4)

Co-authored-by: Christian Klein <167265+cklein@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Miss Islington (bot) 2023-01-04 15:08:37 -08:00 committed by GitHub
parent eba6b00953
commit 541e7b8029
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -647,7 +647,7 @@ class NonCallableMock(Base):
raise AttributeError("Mock object has no attribute %r" % name)
elif _is_magic(name):
raise AttributeError(name)
if not self._mock_unsafe:
if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')):
raise AttributeError(
f"{name!r} is not a valid assertion. Use a spec "