Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8af9db3e
Kaydet (Commit)
8af9db3e
authored
Nis 16, 2014
tarafından
Kushal Das
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Closes Issue 21262: New method assert_not_called for Mock.
It raises AssertionError if the mock has been called.
üst
8c14534d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
0 deletions
+34
-0
unittest.mock.rst
Doc/library/unittest.mock.rst
+14
-0
mock.py
Lib/unittest/mock.py
+8
-0
testmock.py
Lib/unittest/test/testmock/testmock.py
+9
-0
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/unittest.mock.rst
Dosyayı görüntüle @
8af9db3e
...
...
@@ -321,6 +321,20 @@ the `new_callable` argument to `patch`.
>>> calls = [call(4), call(2), call(3)]
>>> mock.assert_has_calls(calls, any_order=True)
.. method:: assert_not_called(*args, **kwargs)
Assert the mock was never called.
>>> m = Mock()
>>> m.hello.assert_not_called()
>>> obj = m.hello()
>>> m.hello.assert_not_called()
Traceback (most recent call last):
...
AssertionError: Expected 'hello' to not have been called. Called 1 times.
.. versionadded:: 3.5
.. method:: reset_mock()
...
...
Lib/unittest/mock.py
Dosyayı görüntüle @
8af9db3e
...
...
@@ -758,6 +758,14 @@ class NonCallableMock(Base):
else
:
return
_call
def
assert_not_called
(
_mock_self
,
*
args
,
**
kwargs
):
"""assert that the mock was never called.
"""
self
=
_mock_self
if
self
.
call_count
!=
0
:
msg
=
(
"Expected '
%
s' to not have been called. Called
%
s times."
%
(
self
.
_mock_name
or
'mock'
,
self
.
call_count
))
raise
AssertionError
(
msg
)
def
assert_called_with
(
_mock_self
,
*
args
,
**
kwargs
):
"""assert that the mock was called with the specified arguments.
...
...
Lib/unittest/test/testmock/testmock.py
Dosyayı görüntüle @
8af9db3e
...
...
@@ -1198,6 +1198,15 @@ class MockTest(unittest.TestCase):
m
.
assert_foo_call
()
m
.
assret_foo_call
()
#Issue21262
def
test_assert_not_called
(
self
):
m
=
Mock
()
m
.
hello
.
assert_not_called
()
m
.
hello
()
with
self
.
assertRaises
(
AssertionError
):
m
.
hello
.
assert_not_called
()
def
test_mock_add_spec
(
self
):
class
_One
(
object
):
one
=
1
...
...
Misc/NEWS
Dosyayı görüntüle @
8af9db3e
...
...
@@ -50,6 +50,9 @@ Core and Builtins
Library
-------
- Issue #21262: New method assert_not_called for Mock.
It raises AssertionError if the mock has been called.
- Issue #21238: New keyword argument `unsafe` to Mock. It raises
`AttributeError` incase of an attribute startswith assert or assret.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment