Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde7a1ce

Browse files
ckleinChristian Klein
authored and
Christian Klein
committed
Respect mock spec when checking for unsafe prefixes
1 parenta286caa commitde7a1ce

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

‎Lib/test/test_unittest/testmock/testmock.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1652,6 +1652,15 @@ def test_mock_unsafe(self):
16521652
m.aseert_foo_call()
16531653
m.assrt_foo_call()
16541654

1655+
# gh-100739
1656+
deftest_mock_safe_with_spec(self):
1657+
classFoo(object):
1658+
defassert_bar(self):
1659+
pass
1660+
1661+
m=Mock(spec=Foo)
1662+
m.assert_bar()
1663+
16551664
#Issue21262
16561665
deftest_assert_not_called(self):
16571666
m=Mock()

‎Lib/unittest/mock.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def __getattr__(self, name):
652652
raiseAttributeError("Mock object has no attribute %r"%name)
653653
elif_is_magic(name):
654654
raiseAttributeError(name)
655-
ifnotself._mock_unsafe:
655+
ifnotself._mock_unsafeand (notself._mock_methodsornamenotinself._mock_methods):
656656
ifname.startswith(('assert','assret','asert','aseert','assrt')):
657657
raiseAttributeError(
658658
f"{name!r} is not a valid assertion. Use a spec "

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp