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

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Christian Klein 2023-01-04 23:31:29 +01:00 committed by GitHub
parent 52017dbe16
commit 7f1eefc6f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -652,7 +652,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 "