chunk_id
stringlengths
36
36
source
stringclasses
35 values
source_url
stringlengths
0
290
upstream_license
stringclasses
1 value
document_id
stringlengths
36
36
chunk_index
int64
0
324k
retrieved_at
stringclasses
2 values
chunker_version
stringclasses
4 values
content_hash
stringlengths
15
64
content
stringlengths
50
44.7k
namespace
stringclasses
9 values
source_name
stringclasses
35 values
raw_text
stringlengths
50
44.7k
cleaned_text
stringlengths
50
44.7k
tags
stringclasses
49 values
collection_name
stringclasses
11 values
78f3cf3b-f3fe-4f21-940b-1c1f252aef2e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,905
supabase-export-v2
2bf7f3ba7e24ea08
introspection and assertions. The positional arguments are a tuple (an empty tuple if there are no positional arguments) and the keyword arguments are a dictionary: >>> m = MagicMock(return_value=None) >>> m(1, 2, 3, arg='one', arg2='two') >>> kall = m.call_args >>> kall.args (1, 2, 3) >>> kall.kwargs {'arg': 'on...
trusted_official_docs
CPython Docs
introspection and assertions. The positional arguments are a tuple (an empty tuple if there are no positional arguments) and the keyword arguments are a dictionary: >>> m = MagicMock(return_value=None) >>> m(1, 2, 3, arg='one', arg2='two') >>> kall = m.call_args >>> kall.args (1, 2, 3) >>> kall.kwargs {'arg': 'on...
introspection and assertions. The positional arguments are a tuple (an empty tuple if there are no positional arguments) and the keyword arguments are a dictionary: >>> m = MagicMock(return_value=None) >>> m(1, 2, 3, arg='one', arg2='two') >>> kall = m.call_args >>> kall.args (1, 2, 3) >>> kall.kwargs {'arg': 'on...
python, official-docs, cpython, P0
Local_Trusted_Corpus
79ed45ec-1747-4ba7-a8c9-f3ccf4b4b78f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,845
supabase-export-v2
a4cb60bf3b7da174
>>> def __str__(self): ... return 'fooble' ... >>> mock = Mock() >>> mock.__str__ = __str__ >>> str(mock) 'fooble' >>> mock = Mock() >>> mock.__str__ = Mock() >>> mock.__str__.return_value = 'fooble' >>> str(mock) 'fooble'
trusted_official_docs
CPython Docs
>>> def __str__(self): ... return 'fooble' ... >>> mock = Mock() >>> mock.__str__ = __str__ >>> str(mock) 'fooble' >>> mock = Mock() >>> mock.__str__ = Mock() >>> mock.__str__.return_value = 'fooble' >>> str(mock) 'fooble'
>>> def __str__(self): ... return 'fooble' ... >>> mock = Mock() >>> mock.__str__ = __str__ >>> str(mock) 'fooble' >>> mock = Mock() >>> mock.__str__ = Mock() >>> mock.__str__.return_value = 'fooble' >>> str(mock) 'fooble'
python, official-docs, cpython, P0
Local_Trusted_Corpus
7a03d38d-aaa9-4da7-bd81-5fd6a251d515
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,500
supabase-export-v2
6370692b8baaee2c
assert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike :meth:`assert_called_with` and :meth:`assert_called_once_with` that only pass if the call is the most recent one, and in the case of :meth:`assert_called_once_with` it must also be the only call...
trusted_official_docs
CPython Docs
assert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike :meth:`assert_called_with` and :meth:`assert_called_once_with` that only pass if the call is the most recent one, and in the case of :meth:`assert_called_once_with` it must also be the only call...
assert the mock has been called with the specified arguments. The assert passes if the mock has *ever* been called, unlike :meth:`assert_called_with` and :meth:`assert_called_once_with` that only pass if the call is the most recent one, and in the case of :meth:`assert_called_once_with` it must also be the only call...
python, official-docs, cpython, P0
Local_Trusted_Corpus
7a1a101b-dd80-4377-8f34-b74e555576d5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,843
supabase-export-v2
8fe76d7fa3c7c227
specific magic methods are supported. The supported list includes *almost* all of them. If there are any missing that you need please let us know. You mock magic methods by setting the method you are interested in to a function or a mock instance. If you are using a function then it *must* take ``self`` as the first ar...
trusted_official_docs
CPython Docs
specific magic methods are supported. The supported list includes *almost* all of them. If there are any missing that you need please let us know. You mock magic methods by setting the method you are interested in to a function or a mock instance. If you are using a function then it *must* take ``self`` as the first ar...
specific magic methods are supported. The supported list includes *almost* all of them. If there are any missing that you need please let us know. You mock magic methods by setting the method you are interested in to a function or a mock instance. If you are using a function then it *must* take ``self`` as the first ar...
python, official-docs, cpython, P0
Local_Trusted_Corpus
7b04cb56-0149-4e11-ba17-d72fef9b5323
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,574
supabase-export-v2
11461a85ac84ecb2
objects. These are tuples, so they can be unpacked to get at the individual arguments and make more complex assertions. See :ref:`calls as tuples <calls-as-tuples>`. .. versionchanged:: 3.8 Added ``args`` and ``kwargs`` properties.
trusted_official_docs
CPython Docs
objects. These are tuples, so they can be unpacked to get at the individual arguments and make more complex assertions. See :ref:`calls as tuples <calls-as-tuples>`. .. versionchanged:: 3.8 Added ``args`` and ``kwargs`` properties.
objects. These are tuples, so they can be unpacked to get at the individual arguments and make more complex assertions. See :ref:`calls as tuples <calls-as-tuples>`. .. versionchanged:: 3.8 Added ``args`` and ``kwargs`` properties.
python, official-docs, cpython, P0
Local_Trusted_Corpus
7bfe58e4-e81a-4124-855d-af7d5b96e990
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,601
supabase-export-v2
b3b1b68a598907d9
the :func:`patch` decorators the keywords are passed to the constructor of the mock being created. The keyword arguments are for configuring attributes of the mock: >>> m = MagicMock(attribute=3, other='fish') >>> m.attribute 3 >>> m.other 'fish'
trusted_official_docs
CPython Docs
the :func:`patch` decorators the keywords are passed to the constructor of the mock being created. The keyword arguments are for configuring attributes of the mock: >>> m = MagicMock(attribute=3, other='fish') >>> m.attribute 3 >>> m.other 'fish'
the :func:`patch` decorators the keywords are passed to the constructor of the mock being created. The keyword arguments are for configuring attributes of the mock: >>> m = MagicMock(attribute=3, other='fish') >>> m.attribute 3 >>> m.other 'fish'
python, official-docs, cpython, P0
Local_Trusted_Corpus
7c1da5e4-5d67-414f-9577-f77ff1f707b0
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,433
supabase-export-v2
29fc200b91a948aa
of a test, along with :const:`sentinel` for creating unique objects. See the `quick guide`_ for some examples of how to use :class:`Mock`, :class:`MagicMock` and :func:`patch`. Mock is designed for use with :mod:`unittest` and is based on the 'action -> assertion' pattern instead of 'record -> replay' used by many mock...
trusted_official_docs
CPython Docs
of a test, along with :const:`sentinel` for creating unique objects. See the `quick guide`_ for some examples of how to use :class:`Mock`, :class:`MagicMock` and :func:`patch`. Mock is designed for use with :mod:`unittest` and is based on the 'action -> assertion' pattern instead of 'record -> replay' used by many mock...
of a test, along with :const:`sentinel` for creating unique objects. See the `quick guide`_ for some examples of how to use :class:`Mock`, :class:`MagicMock` and :func:`patch`. Mock is designed for use with :mod:`unittest` and is based on the 'action -> assertion' pattern instead of 'record -> replay' used by many mock...
python, official-docs, cpython, P0
Local_Trusted_Corpus
7c40c61b-d3e0-4c1b-936e-a53ef072324b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
27,007
supabase-export-v2
8993e79ee457bbb0
The order of precedence will ignore this value and it will move to the last successor which is the wrapped object. As the real call is being made to the wrapped object, creating an instance of this mock will return the real instance of the class. The positional arguments, if any, required by the wrapped object must be ...
trusted_official_docs
CPython Docs
The order of precedence will ignore this value and it will move to the last successor which is the wrapped object. As the real call is being made to the wrapped object, creating an instance of this mock will return the real instance of the class. The positional arguments, if any, required by the wrapped object must be ...
The order of precedence will ignore this value and it will move to the last successor which is the wrapped object. As the real call is being made to the wrapped object, creating an instance of this mock will return the real instance of the class. The positional arguments, if any, required by the wrapped object must be ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
7cf7ef5c-cc57-496d-89e9-d05f3dd83660
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,778
supabase-export-v2
0d5ab8efc3f6bf95
used to add members to a dictionary, or simply let a test change a dictionary, and ensure the dictionary is restored when the test ends. >>> foo = {} >>> with patch.dict(foo, {'newkey': 'newvalue'}) as patched_foo: ... assert foo == {'newkey': 'newvalue'} ... assert patched_foo == {'newkey': 'newvalue'} ... # You c...
trusted_official_docs
CPython Docs
used to add members to a dictionary, or simply let a test change a dictionary, and ensure the dictionary is restored when the test ends. >>> foo = {} >>> with patch.dict(foo, {'newkey': 'newvalue'}) as patched_foo: ... assert foo == {'newkey': 'newvalue'} ... assert patched_foo == {'newkey': 'newvalue'} ... # You c...
used to add members to a dictionary, or simply let a test change a dictionary, and ensure the dictionary is restored when the test ends. >>> foo = {} >>> with patch.dict(foo, {'newkey': 'newvalue'}) as patched_foo: ... assert foo == {'newkey': 'newvalue'} ... assert patched_foo == {'newkey': 'newvalue'} ... # You c...
python, official-docs, cpython, P0
Local_Trusted_Corpus
7ec14657-cab1-40aa-95ab-85c2956e690e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,559
supabase-export-v2
cb4056dbd445456a
the mock will then return whatever the function returns. If the function returns :data:`DEFAULT` then the mock will return its normal value (from the :attr:`return_value`). If you pass in an iterable, it is used to retrieve an iterator which must yield a value on every call. This value can either be an exception inst...
trusted_official_docs
CPython Docs
the mock will then return whatever the function returns. If the function returns :data:`DEFAULT` then the mock will return its normal value (from the :attr:`return_value`). If you pass in an iterable, it is used to retrieve an iterator which must yield a value on every call. This value can either be an exception inst...
the mock will then return whatever the function returns. If the function returns :data:`DEFAULT` then the mock will return its normal value (from the :attr:`return_value`). If you pass in an iterable, it is used to retrieve an iterator which must yield a value on every call. This value can either be an exception inst...
python, official-docs, cpython, P0
Local_Trusted_Corpus
80133f9e-4057-46c0-af60-b015b59c67bc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,911
supabase-export-v2
fff716a73ff25be8
Functions or methods being mocked will have their arguments checked to ensure that they are called with the correct signature. If *spec_set* is ``True`` then attempting to set attributes that don't exist on the spec object will raise an :exc:`AttributeError`.
trusted_official_docs
CPython Docs
Functions or methods being mocked will have their arguments checked to ensure that they are called with the correct signature. If *spec_set* is ``True`` then attempting to set attributes that don't exist on the spec object will raise an :exc:`AttributeError`.
Functions or methods being mocked will have their arguments checked to ensure that they are called with the correct signature. If *spec_set* is ``True`` then attempting to set attributes that don't exist on the spec object will raise an :exc:`AttributeError`.
python, official-docs, cpython, P0
Local_Trusted_Corpus
8029cea6-f9bc-4e89-b79e-98fe599c6abd
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,848
supabase-export-v2
5c1c4708e715d995
One use case for this is for mocking objects used as context managers in a :keyword:`with` statement: >>> mock = Mock() >>> mock.__enter__ = Mock(return_value='foo') >>> mock.__exit__ = Mock(return_value=False) >>> with mock as m: ... assert m == 'foo' ... >>> mock.__enter__.assert_called_with() >>> mock.__exit__...
trusted_official_docs
CPython Docs
One use case for this is for mocking objects used as context managers in a :keyword:`with` statement: >>> mock = Mock() >>> mock.__enter__ = Mock(return_value='foo') >>> mock.__exit__ = Mock(return_value=False) >>> with mock as m: ... assert m == 'foo' ... >>> mock.__enter__.assert_called_with() >>> mock.__exit__...
One use case for this is for mocking objects used as context managers in a :keyword:`with` statement: >>> mock = Mock() >>> mock.__enter__ = Mock(return_value='foo') >>> mock.__exit__ = Mock(return_value=False) >>> with mock as m: ... assert m == 'foo' ... >>> mock.__enter__.assert_called_with() >>> mock.__exit__...
python, official-docs, cpython, P0
Local_Trusted_Corpus
80cbae9a-d73a-409e-ace5-630a4611962d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,903
supabase-export-v2
0946845868dd1f6b
interesting, but the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock.call_args_list` and :attr:`Mock.mock_calls` attributes can be introspected to get at the individual arguments they contain. The ``call`` objects in :attr:`Mock.call_args` and :attr:`Mock.call_args_list` are two-tuples of (position...
trusted_official_docs
CPython Docs
interesting, but the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock.call_args_list` and :attr:`Mock.mock_calls` attributes can be introspected to get at the individual arguments they contain. The ``call`` objects in :attr:`Mock.call_args` and :attr:`Mock.call_args_list` are two-tuples of (position...
interesting, but the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock.call_args_list` and :attr:`Mock.mock_calls` attributes can be introspected to get at the individual arguments they contain. The ``call`` objects in :attr:`Mock.call_args` and :attr:`Mock.call_args_list` are two-tuples of (position...
python, official-docs, cpython, P0
Local_Trusted_Corpus
80d0a40d-d37d-42fc-9595-a679b5fc193a
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,854
supabase-export-v2
013a481d09537151
``__set__`` and ``__delete__`` * Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, ``__getstate__`` and ``__setstate__`` * File system path representation: ``__fspath__`` * Asynchronous iteration methods: ``__aiter__`` and ``__anext__`` .. versionchanged:: 3.8 Added support for :fun...
trusted_official_docs
CPython Docs
``__set__`` and ``__delete__`` * Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, ``__getstate__`` and ``__setstate__`` * File system path representation: ``__fspath__`` * Asynchronous iteration methods: ``__aiter__`` and ``__anext__`` .. versionchanged:: 3.8 Added support for :fun...
``__set__`` and ``__delete__`` * Pickling: ``__reduce__``, ``__reduce_ex__``, ``__getinitargs__``, ``__getnewargs__``, ``__getstate__`` and ``__setstate__`` * File system path representation: ``__fspath__`` * Asynchronous iteration methods: ``__aiter__`` and ``__anext__`` .. versionchanged:: 3.8 Added support for :fun...
python, official-docs, cpython, P0
Local_Trusted_Corpus
82bdd85c-5706-479c-a44e-f38bcba99004
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,787
supabase-export-v2
087d47e2df1d3ebf
takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ...
trusted_official_docs
CPython Docs
takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ...
takes the object to be patched (either as an object or a string to fetch the object by importing) and keyword arguments for the patches:: with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
833ec7b9-1115-44e2-b523-493c24d9eadc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,881
supabase-export-v2
8c383435b8365cc2
all of the supported magic methods configured except for some of the obscure and obsolete ones. You can still set these up if you want. Magic methods that are supported but not setup by default in ``MagicMock`` are:
trusted_official_docs
CPython Docs
all of the supported magic methods configured except for some of the obscure and obsolete ones. You can still set these up if you want. Magic methods that are supported but not setup by default in ``MagicMock`` are:
all of the supported magic methods configured except for some of the obscure and obsolete ones. You can still set these up if you want. Magic methods that are supported but not setup by default in ``MagicMock`` are:
python, official-docs, cpython, P0
Local_Trusted_Corpus
8364632b-ec74-4dd0-8e34-98b4b5efde2e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,791
supabase-export-v2
7706f8a15f196048
When used as a class decorator :func:`patch.multiple` honours ``patch.TEST_PREFIX`` for choosing which methods to wrap. If you want :func:`patch.multiple` to create mocks for you, then you can use :data:`DEFAULT` as the value. If you use :func:`patch.multiple` as a decorator then the created mocks are passed into the d...
trusted_official_docs
CPython Docs
When used as a class decorator :func:`patch.multiple` honours ``patch.TEST_PREFIX`` for choosing which methods to wrap. If you want :func:`patch.multiple` to create mocks for you, then you can use :data:`DEFAULT` as the value. If you use :func:`patch.multiple` as a decorator then the created mocks are passed into the d...
When used as a class decorator :func:`patch.multiple` honours ``patch.TEST_PREFIX`` for choosing which methods to wrap. If you want :func:`patch.multiple` to create mocks for you, then you can use :data:`DEFAULT` as the value. If you use :func:`patch.multiple` as a decorator then the created mocks are passed into the d...
python, official-docs, cpython, P0
Local_Trusted_Corpus
84a1b8ce-65ba-4309-876a-5473162fac8f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,673
supabase-export-v2
69236a0cde537dbd
If a timeout was passed at the creation of the mock the function raises an :exc:`AssertionError` if the call is not performed in time. >>> mock = ThreadingMock() >>> thread = threading.Thread(target=mock, args=("arg1", "arg2",), kwargs={"arg": "thing"}) >>> thread.start() >>> mock.wait_until_any_call_with("arg1", "a...
trusted_official_docs
CPython Docs
If a timeout was passed at the creation of the mock the function raises an :exc:`AssertionError` if the call is not performed in time. >>> mock = ThreadingMock() >>> thread = threading.Thread(target=mock, args=("arg1", "arg2",), kwargs={"arg": "thing"}) >>> thread.start() >>> mock.wait_until_any_call_with("arg1", "a...
If a timeout was passed at the creation of the mock the function raises an :exc:`AssertionError` if the call is not performed in time. >>> mock = ThreadingMock() >>> thread = threading.Thread(target=mock, args=("arg1", "arg2",), kwargs={"arg": "thing"}) >>> thread.start() >>> mock.wait_until_any_call_with("arg1", "a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
85959173-a72a-4281-b3e4-2c7aaae37d74
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,810
supabase-export-v2
9ef7e39eaffe0508
As an added bonus you no longer need to keep a reference to the ``patcher`` object. It is also possible to stop all patches which have been started by using :func:`patch.stopall`.
trusted_official_docs
CPython Docs
As an added bonus you no longer need to keep a reference to the ``patcher`` object. It is also possible to stop all patches which have been started by using :func:`patch.stopall`.
As an added bonus you no longer need to keep a reference to the ``patcher`` object. It is also possible to stop all patches which have been started by using :func:`patch.stopall`.
python, official-docs, cpython, P0
Local_Trusted_Corpus
8673f0eb-9f11-4386-9d00-8bd457698fc8
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,684
supabase-export-v2
74fb647513b57d9c
>>> def side_effect(value): ... return value + 1 ... >>> m = MagicMock(side_effect=side_effect) >>> m(1) 2 >>> m(2) 3 >>> m.mock_calls [call(1), call(2)] If you want the mock to still return the default return value (a new mock), or any set return value, then there are two ways of doing this. Either return :attr:`~Mock...
trusted_official_docs
CPython Docs
>>> def side_effect(value): ... return value + 1 ... >>> m = MagicMock(side_effect=side_effect) >>> m(1) 2 >>> m(2) 3 >>> m.mock_calls [call(1), call(2)] If you want the mock to still return the default return value (a new mock), or any set return value, then there are two ways of doing this. Either return :attr:`~Mock...
>>> def side_effect(value): ... return value + 1 ... >>> m = MagicMock(side_effect=side_effect) >>> m(1) 2 >>> m(2) 3 >>> m.mock_calls [call(1), call(2)] If you want the mock to still return the default return value (a new mock), or any set return value, then there are two ways of doing this. Either return :attr:`~Mock...
python, official-docs, cpython, P0
Local_Trusted_Corpus
86da630f-4509-47c7-ab96-4931ea41a8b0
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,823
supabase-export-v2
2399b4677ae8343b
You can stack up multiple patch decorators using this pattern: >>> @patch.object(SomeClass, 'class_method') ... @patch.object(SomeClass, 'static_method') ... def test(mock1, mock2): ... assert SomeClass.static_method is mock1 ... assert SomeClass.class_method is mock2 ... SomeClass.static_method('foo') ... SomeCl...
trusted_official_docs
CPython Docs
You can stack up multiple patch decorators using this pattern: >>> @patch.object(SomeClass, 'class_method') ... @patch.object(SomeClass, 'static_method') ... def test(mock1, mock2): ... assert SomeClass.static_method is mock1 ... assert SomeClass.class_method is mock2 ... SomeClass.static_method('foo') ... SomeCl...
You can stack up multiple patch decorators using this pattern: >>> @patch.object(SomeClass, 'class_method') ... @patch.object(SomeClass, 'static_method') ... def test(mock1, mock2): ... assert SomeClass.static_method is mock1 ... assert SomeClass.class_method is mock2 ... SomeClass.static_method('foo') ... SomeCl...
python, official-docs, cpython, P0
Local_Trusted_Corpus
87381d54-4d77-49eb-8f2e-0b25748ab2d5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,461
supabase-export-v2
f5ad57e90d820451
This ensures that your mocks will fail in the same way as your production code if they are used incorrectly: >>> from unittest.mock import create_autospec >>> def function(a, b, c): ... pass ... >>> mock_function = create_autospec(function, return_value='fishy') >>> mock_function(1, 2, 3) 'fishy' >>> mock_functio...
trusted_official_docs
CPython Docs
This ensures that your mocks will fail in the same way as your production code if they are used incorrectly: >>> from unittest.mock import create_autospec >>> def function(a, b, c): ... pass ... >>> mock_function = create_autospec(function, return_value='fishy') >>> mock_function(1, 2, 3) 'fishy' >>> mock_functio...
This ensures that your mocks will fail in the same way as your production code if they are used incorrectly: >>> from unittest.mock import create_autospec >>> def function(a, b, c): ... pass ... >>> mock_function = create_autospec(function, return_value='fishy') >>> mock_function(1, 2, 3) 'fishy' >>> mock_functio...
python, official-docs, cpython, P0
Local_Trusted_Corpus
878aff48-552a-48cb-afcf-02ee54427936
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,803
supabase-export-v2
7b0e24472f1bc922
If you are using :func:`patch` to create a mock for you then it will be returned by the call to ``patcher.start``. :: >>> patcher = patch('package.module.ClassName') >>> from package import module >>> original = module.ClassName >>> new_mock = patcher.start() >>> assert module.ClassName is not original >>> assert ...
trusted_official_docs
CPython Docs
If you are using :func:`patch` to create a mock for you then it will be returned by the call to ``patcher.start``. :: >>> patcher = patch('package.module.ClassName') >>> from package import module >>> original = module.ClassName >>> new_mock = patcher.start() >>> assert module.ClassName is not original >>> assert ...
If you are using :func:`patch` to create a mock for you then it will be returned by the call to ``patcher.start``. :: >>> patcher = patch('package.module.ClassName') >>> from package import module >>> original = module.ClassName >>> new_mock = patcher.start() >>> assert module.ClassName is not original >>> assert ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
879dbd11-887f-4db7-99fd-fb4e95099662
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,596
supabase-export-v2
28d60016a7a896d9
.. class:: NonCallableMock(spec=None, wraps=None, name=None, spec_set=None, **kwargs) A non-callable version of :class:`Mock`. The constructor parameters have the same meaning of :class:`Mock`, with the exception of *return_value* and *side_effect* which have no meaning on a non-callable mock.
trusted_official_docs
CPython Docs
.. class:: NonCallableMock(spec=None, wraps=None, name=None, spec_set=None, **kwargs) A non-callable version of :class:`Mock`. The constructor parameters have the same meaning of :class:`Mock`, with the exception of *return_value* and *side_effect* which have no meaning on a non-callable mock.
.. class:: NonCallableMock(spec=None, wraps=None, name=None, spec_set=None, **kwargs) A non-callable version of :class:`Mock`. The constructor parameters have the same meaning of :class:`Mock`, with the exception of *return_value* and *side_effect* which have no meaning on a non-callable mock.
python, official-docs, cpython, P0
Local_Trusted_Corpus
8826f5e7-5132-4634-bfc1-73b902f0bae3
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,977
supabase-export-v2
5242adf50cdffe18
... >>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a ... Traceback (most recent call last): ... AttributeError: Mock object has no attribute 'a' There are a few different ways of resolving this problem. The easiest, but not necessarily the least annoying, way is to simply set the...
trusted_official_docs
CPython Docs
... >>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a ... Traceback (most recent call last): ... AttributeError: Mock object has no attribute 'a' There are a few different ways of resolving this problem. The easiest, but not necessarily the least annoying, way is to simply set the...
... >>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a ... Traceback (most recent call last): ... AttributeError: Mock object has no attribute 'a' There are a few different ways of resolving this problem. The easiest, but not necessarily the least annoying, way is to simply set the...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8988a137-4bb4-40b8-bd0f-9861f77db672
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,465
supabase-export-v2
72a366c5e50a32e7
import threading from unittest.mock import sentinel, DEFAULT, ANY from unittest.mock import patch, call, Mock, MagicMock, PropertyMock, AsyncMock from unittest.mock import ThreadingMock from unittest.mock import mock_open :class:`Mock` is a flexible mock object intended to replace the use of stubs and test doubles thro...
trusted_official_docs
CPython Docs
import threading from unittest.mock import sentinel, DEFAULT, ANY from unittest.mock import patch, call, Mock, MagicMock, PropertyMock, AsyncMock from unittest.mock import ThreadingMock from unittest.mock import mock_open :class:`Mock` is a flexible mock object intended to replace the use of stubs and test doubles thro...
import threading from unittest.mock import sentinel, DEFAULT, ANY from unittest.mock import patch, call, Mock, MagicMock, PropertyMock, AsyncMock from unittest.mock import ThreadingMock from unittest.mock import mock_open :class:`Mock` is a flexible mock object intended to replace the use of stubs and test doubles thro...
python, official-docs, cpython, P0
Local_Trusted_Corpus
89c81a8b-3961-499a-a6a7-b6a802f81665
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,612
supabase-export-v2
71e05a23ecbad7bb
with patch('__main__.Foo.foo', new_callable=PropertyMock) as mock_foo: ... mock_foo.return_value = 'mockity-mock' ... this_foo = Foo() ... print(this_foo.foo) ... this_foo.foo = 6 ... mockity-mock >>> mock_foo.mock_calls [call(), call(6)] Because of the way mock attributes are stored you can't directly attach a :class:...
trusted_official_docs
CPython Docs
with patch('__main__.Foo.foo', new_callable=PropertyMock) as mock_foo: ... mock_foo.return_value = 'mockity-mock' ... this_foo = Foo() ... print(this_foo.foo) ... this_foo.foo = 6 ... mockity-mock >>> mock_foo.mock_calls [call(), call(6)] Because of the way mock attributes are stored you can't directly attach a :class:...
with patch('__main__.Foo.foo', new_callable=PropertyMock) as mock_foo: ... mock_foo.return_value = 'mockity-mock' ... this_foo = Foo() ... print(this_foo.foo) ... this_foo.foo = 6 ... mockity-mock >>> mock_foo.mock_calls [call(), call(6)] Because of the way mock attributes are stored you can't directly attach a :class:...
python, official-docs, cpython, P0
Local_Trusted_Corpus
8c605f54-f12a-4fdc-801c-a414501754fe
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,665
supabase-export-v2
b49eb8ae76262bd1
The default timeout is specified by the ``timeout`` argument, or if unset by the :attr:`ThreadingMock.DEFAULT_TIMEOUT` attribute, which defaults to blocking (``None``). You can configure the global default timeout by setting :attr:`ThreadingMock.DEFAULT_TIMEOUT`.
trusted_official_docs
CPython Docs
The default timeout is specified by the ``timeout`` argument, or if unset by the :attr:`ThreadingMock.DEFAULT_TIMEOUT` attribute, which defaults to blocking (``None``). You can configure the global default timeout by setting :attr:`ThreadingMock.DEFAULT_TIMEOUT`.
The default timeout is specified by the ``timeout`` argument, or if unset by the :attr:`ThreadingMock.DEFAULT_TIMEOUT` attribute, which defaults to blocking (``None``). You can configure the global default timeout by setting :attr:`ThreadingMock.DEFAULT_TIMEOUT`.
python, official-docs, cpython, P0
Local_Trusted_Corpus
8e08ca22-f263-41eb-b317-67cf89fd8139
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,863
supabase-export-v2
6b68c1dba344c68a
The constructor parameters have the same meaning as for :class:`Mock`. If you use the *spec* or *spec_set* arguments then *only* magic methods that exist in the spec will be created.
trusted_official_docs
CPython Docs
The constructor parameters have the same meaning as for :class:`Mock`. If you use the *spec* or *spec_set* arguments then *only* magic methods that exist in the spec will be created.
The constructor parameters have the same meaning as for :class:`Mock`. If you use the *spec* or *spec_set* arguments then *only* magic methods that exist in the spec will be created.
python, official-docs, cpython, P0
Local_Trusted_Corpus
92d1d601-8091-4afe-b12f-316fd8bc03a4
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,655
supabase-export-v2
c8a6e17e24586711
An integer keeping track of how many times the mock object has been awaited. >>> mock = AsyncMock() >>> async def main(): ... await mock() ... >>> asyncio.run(main()) >>> mock.await_count 1 >>> asyncio.run(main()) >>> mock.await_count 2
trusted_official_docs
CPython Docs
An integer keeping track of how many times the mock object has been awaited. >>> mock = AsyncMock() >>> async def main(): ... await mock() ... >>> asyncio.run(main()) >>> mock.await_count 1 >>> asyncio.run(main()) >>> mock.await_count 2
An integer keeping track of how many times the mock object has been awaited. >>> mock = AsyncMock() >>> async def main(): ... await mock() ... >>> asyncio.run(main()) >>> mock.await_count 1 >>> asyncio.run(main()) >>> mock.await_count 2
python, official-docs, cpython, P0
Local_Trusted_Corpus
93391882-3807-470c-aaad-805d40bedafb
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,805
supabase-export-v2
04e055648d8c06e7
A typical use case for this might be for doing multiple patches in the ``setUp`` method of a :class:`~unittest.TestCase`:: >>> class MyTest(unittest.TestCase): ... def setUp(self): ... self.patcher1 = patch('package.module.Class1') ... self.patcher2 = patch('package.module.Class2') ... self.MockClass1 = self.patche...
trusted_official_docs
CPython Docs
A typical use case for this might be for doing multiple patches in the ``setUp`` method of a :class:`~unittest.TestCase`:: >>> class MyTest(unittest.TestCase): ... def setUp(self): ... self.patcher1 = patch('package.module.Class1') ... self.patcher2 = patch('package.module.Class2') ... self.MockClass1 = self.patche...
A typical use case for this might be for doing multiple patches in the ``setUp`` method of a :class:`~unittest.TestCase`:: >>> class MyTest(unittest.TestCase): ... def setUp(self): ... self.patcher1 = patch('package.module.Class1') ... self.patcher2 = patch('package.module.Class2') ... self.MockClass1 = self.patche...
python, official-docs, cpython, P0
Local_Trusted_Corpus
947fbb82-f734-4b8b-8572-a0ea82a1afa5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,430
supabase-export-v2
4490dd9f7ea8f9d7
-------------- :mod:`!unittest.mock` is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
trusted_official_docs
CPython Docs
-------------- :mod:`!unittest.mock` is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
-------------- :mod:`!unittest.mock` is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used.
python, official-docs, cpython, P0
Local_Trusted_Corpus
9528d212-0ef9-48f3-ab32-3c4510b2002d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,578
supabase-export-v2
c441a0fdea904e95
>>> mock(key='fish', next='w00t!') >>> mock.call_args_list [call(), call(3, 4), call(key='fish', next='w00t!')] >>> expected = [(), ((3, 4),), ({'key': 'fish', 'next': 'w00t!'},)] >>> mock.call_args_list == expected True Members of :attr:`call_args_list` are :data:`call` objects. These can be unpacked as tuples to get...
trusted_official_docs
CPython Docs
>>> mock(key='fish', next='w00t!') >>> mock.call_args_list [call(), call(3, 4), call(key='fish', next='w00t!')] >>> expected = [(), ((3, 4),), ({'key': 'fish', 'next': 'w00t!'},)] >>> mock.call_args_list == expected True Members of :attr:`call_args_list` are :data:`call` objects. These can be unpacked as tuples to get...
>>> mock(key='fish', next='w00t!') >>> mock.call_args_list [call(), call(3, 4), call(key='fish', next='w00t!')] >>> expected = [(), ((3, 4),), ({'key': 'fish', 'next': 'w00t!'},)] >>> mock.call_args_list == expected True Members of :attr:`call_args_list` are :data:`call` objects. These can be unpacked as tuples to get...
python, official-docs, cpython, P0
Local_Trusted_Corpus
955feab8-f4e8-4acb-91c2-8a9e01f85809
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,879
supabase-export-v2
bcfa2d9e58aa9e32
If the return value *is* an iterator, then iterating over it once will consume it and subsequent iterations will result in an empty list: >>> mock.__iter__.return_value = iter(['a', 'b', 'c']) >>> list(mock) ['a', 'b', 'c'] >>> list(mock) []
trusted_official_docs
CPython Docs
If the return value *is* an iterator, then iterating over it once will consume it and subsequent iterations will result in an empty list: >>> mock.__iter__.return_value = iter(['a', 'b', 'c']) >>> list(mock) ['a', 'b', 'c'] >>> list(mock) []
If the return value *is* an iterator, then iterating over it once will consume it and subsequent iterations will result in an empty list: >>> mock.__iter__.return_value = iter(['a', 'b', 'c']) >>> list(mock) ['a', 'b', 'c'] >>> list(mock) []
python, official-docs, cpython, P0
Local_Trusted_Corpus
95fedd16-a772-4329-8df2-2bdb366f2412
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,745
supabase-export-v2
efe5418e6bb810de
>>> patcher = patch('__main__.thing', first='one', second='two') >>> mock_thing = patcher.start() >>> mock_thing.first 'one' >>> mock_thing.second 'two' As well as attributes on the created mock attributes, like the :attr:`~Mock.return_value` and :attr:`~Mock.side_effect`, of child mocks can also be configured. These a...
trusted_official_docs
CPython Docs
>>> patcher = patch('__main__.thing', first='one', second='two') >>> mock_thing = patcher.start() >>> mock_thing.first 'one' >>> mock_thing.second 'two' As well as attributes on the created mock attributes, like the :attr:`~Mock.return_value` and :attr:`~Mock.side_effect`, of child mocks can also be configured. These a...
>>> patcher = patch('__main__.thing', first='one', second='two') >>> mock_thing = patcher.start() >>> mock_thing.first 'one' >>> mock_thing.second 'two' As well as attributes on the created mock attributes, like the :attr:`~Mock.return_value` and :attr:`~Mock.side_effect`, of child mocks can also be configured. These a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
970df6de-5713-462d-b642-9fd5bf0b0c34
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,773
supabase-export-v2
f6082e2cff933ba8
:func:`patch.dict` can be used as a context manager, decorator or class decorator: >>> foo = {} >>> @patch.dict(foo, {'newkey': 'newvalue'}) ... def test(): ... assert foo == {'newkey': 'newvalue'} ... >>> test() >>> assert foo == {}
trusted_official_docs
CPython Docs
:func:`patch.dict` can be used as a context manager, decorator or class decorator: >>> foo = {} >>> @patch.dict(foo, {'newkey': 'newvalue'}) ... def test(): ... assert foo == {'newkey': 'newvalue'} ... >>> test() >>> assert foo == {}
:func:`patch.dict` can be used as a context manager, decorator or class decorator: >>> foo = {} >>> @patch.dict(foo, {'newkey': 'newvalue'}) ... def test(): ... assert foo == {'newkey': 'newvalue'} ... >>> test() >>> assert foo == {}
python, official-docs, cpython, P0
Local_Trusted_Corpus
9740b707-e708-49d1-9cb8-ffb7070bd914
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,681
supabase-export-v2
2d731491c286cdf8
The simplest way to make a mock raise an exception when called is to make :attr:`~Mock.side_effect` an exception class or instance: >>> m = MagicMock(side_effect=IndexError) >>> m(1, 2, 3) Traceback (most recent call last): ... IndexError >>> m.mock_calls [call(1, 2, 3)] >>> m.side_effect = KeyError('Bang!') >>>...
trusted_official_docs
CPython Docs
The simplest way to make a mock raise an exception when called is to make :attr:`~Mock.side_effect` an exception class or instance: >>> m = MagicMock(side_effect=IndexError) >>> m(1, 2, 3) Traceback (most recent call last): ... IndexError >>> m.mock_calls [call(1, 2, 3)] >>> m.side_effect = KeyError('Bang!') >>>...
The simplest way to make a mock raise an exception when called is to make :attr:`~Mock.side_effect` an exception class or instance: >>> m = MagicMock(side_effect=IndexError) >>> m(1, 2, 3) Traceback (most recent call last): ... IndexError >>> m.mock_calls [call(1, 2, 3)] >>> m.side_effect = KeyError('Bang!') >>>...
python, official-docs, cpython, P0
Local_Trusted_Corpus
99dbac4f-5700-4d9d-b62f-f64c43eec82e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,609
supabase-export-v2
0fdf104a01809c8e
.. class:: PropertyMock(*args, **kwargs) A mock intended to be used as a :class:`property`, or other :term:`descriptor`, on a class. :class:`PropertyMock` provides :meth:`~object.__get__` and :meth:`~object.__set__` methods so you can specify a return value when it is fetched.
trusted_official_docs
CPython Docs
.. class:: PropertyMock(*args, **kwargs) A mock intended to be used as a :class:`property`, or other :term:`descriptor`, on a class. :class:`PropertyMock` provides :meth:`~object.__get__` and :meth:`~object.__set__` methods so you can specify a return value when it is fetched.
.. class:: PropertyMock(*args, **kwargs) A mock intended to be used as a :class:`property`, or other :term:`descriptor`, on a class. :class:`PropertyMock` provides :meth:`~object.__get__` and :meth:`~object.__set__` methods so you can specify a return value when it is fetched.
python, official-docs, cpython, P0
Local_Trusted_Corpus
9a2ecf6a-312b-4207-8b05-73ef3e9c100e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,934
supabase-export-v2
e7d02a20d956dd7b
>>> from unittest import mock >>> mock.FILTER_DIR = False >>> dir(mock.Mock()) ['_NonCallableMock__get_return_value', '_NonCallableMock__get_side_effect', '_NonCallableMock__return_value_doc', '_NonCallableMock__set_return_value', '_NonCallableMock__set_side_effect', '__call__', '__class__', ... Alternatively you can j...
trusted_official_docs
CPython Docs
>>> from unittest import mock >>> mock.FILTER_DIR = False >>> dir(mock.Mock()) ['_NonCallableMock__get_return_value', '_NonCallableMock__get_side_effect', '_NonCallableMock__return_value_doc', '_NonCallableMock__set_return_value', '_NonCallableMock__set_side_effect', '__call__', '__class__', ... Alternatively you can j...
>>> from unittest import mock >>> mock.FILTER_DIR = False >>> dir(mock.Mock()) ['_NonCallableMock__get_return_value', '_NonCallableMock__get_side_effect', '_NonCallableMock__return_value_doc', '_NonCallableMock__set_return_value', '_NonCallableMock__set_side_effect', '__call__', '__class__', ... Alternatively you can j...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9b31cac4-bab4-4d01-8d21-48c7f9557a16
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,999
supabase-export-v2
a84881aea3166040
the one with the higher precedence will return the value. Regardless of the order of which was set first, the order of precedence remains unchanged. >>> from unittest.mock import Mock >>> class Order: ... @staticmethod ... def get_value(): ... return "third" ... >>> order_mock = Mock(spec=Order, wraps=Order) >>> ...
trusted_official_docs
CPython Docs
the one with the higher precedence will return the value. Regardless of the order of which was set first, the order of precedence remains unchanged. >>> from unittest.mock import Mock >>> class Order: ... @staticmethod ... def get_value(): ... return "third" ... >>> order_mock = Mock(spec=Order, wraps=Order) >>> ...
the one with the higher precedence will return the value. Regardless of the order of which was set first, the order of precedence remains unchanged. >>> from unittest.mock import Mock >>> class Order: ... @staticmethod ... def get_value(): ... return "third" ... >>> order_mock = Mock(spec=Order, wraps=Order) >>> ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9bf857ec-8812-4187-bf21-127e1432c97e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,616
supabase-export-v2
3bd7273bb09ec472
If an :exc:`AttributeError` is raised by :class:`PropertyMock`, it will be interpreted as a missing descriptor and :meth:`~object.__getattr__` will be called on the parent mock:: >>> m = MagicMock() >>> no_attribute = PropertyMock(side_effect=AttributeError) >>> type(m).my_property = no_attribute >>> m.my_property ...
trusted_official_docs
CPython Docs
If an :exc:`AttributeError` is raised by :class:`PropertyMock`, it will be interpreted as a missing descriptor and :meth:`~object.__getattr__` will be called on the parent mock:: >>> m = MagicMock() >>> no_attribute = PropertyMock(side_effect=AttributeError) >>> type(m).my_property = no_attribute >>> m.my_property ...
If an :exc:`AttributeError` is raised by :class:`PropertyMock`, it will be interpreted as a missing descriptor and :meth:`~object.__getattr__` will be called on the parent mock:: >>> m = MagicMock() >>> no_attribute = PropertyMock(side_effect=AttributeError) >>> type(m).my_property = no_attribute >>> m.my_property ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
9ea30f60-54bb-499a-97e2-bdd60d29b9bc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,759
supabase-export-v2
add3378d0c769d39
arguments or two arguments. The three argument form takes the object to be patched, the attribute name and the object to replace the attribute with. When calling with the two argument form you omit the replacement object, and a mock is created for you and passed in as an extra argument to the decorated function:
trusted_official_docs
CPython Docs
arguments or two arguments. The three argument form takes the object to be patched, the attribute name and the object to replace the attribute with. When calling with the two argument form you omit the replacement object, and a mock is created for you and passed in as an extra argument to the decorated function:
arguments or two arguments. The three argument form takes the object to be patched, the attribute name and the object to replace the attribute with. When calling with the two argument form you omit the replacement object, and a mock is created for you and passed in as an extra argument to the decorated function:
python, official-docs, cpython, P0
Local_Trusted_Corpus
9fae9871-f875-4c24-8b3e-996b152c85cc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,680
supabase-export-v2
a49093fb716d8e54
:attr:`~Mock.side_effect` is set then it will be called after the call has been recorded, so if :attr:`!side_effect` raises an exception the call is still recorded. The simplest way to make a mock raise an exception when called is to make :attr:`~Mock.side_effect` an exception class or instance:
trusted_official_docs
CPython Docs
:attr:`~Mock.side_effect` is set then it will be called after the call has been recorded, so if :attr:`!side_effect` raises an exception the call is still recorded. The simplest way to make a mock raise an exception when called is to make :attr:`~Mock.side_effect` an exception class or instance:
:attr:`~Mock.side_effect` is set then it will be called after the call has been recorded, so if :attr:`!side_effect` raises an exception the call is still recorded. The simplest way to make a mock raise an exception when called is to make :attr:`~Mock.side_effect` an exception class or instance:
python, official-docs, cpython, P0
Local_Trusted_Corpus
9fcff3f8-c63c-4187-b5de-d40136c5bf7c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,483
supabase-export-v2
f1f81907a0628817
name then it will be used in the repr of the mock. This can be useful for debugging. The name is propagated to child mocks. Mocks can also be called with arbitrary keyword arguments. These will be used to set attributes on the mock after it is created. See the :meth:`configure_mock` method for details.
trusted_official_docs
CPython Docs
name then it will be used in the repr of the mock. This can be useful for debugging. The name is propagated to child mocks. Mocks can also be called with arbitrary keyword arguments. These will be used to set attributes on the mock after it is created. See the :meth:`configure_mock` method for details.
name then it will be used in the repr of the mock. This can be useful for debugging. The name is propagated to child mocks. Mocks can also be called with arbitrary keyword arguments. These will be used to set attributes on the mock after it is created. See the :meth:`configure_mock` method for details.
python, official-docs, cpython, P0
Local_Trusted_Corpus
a0cfa4d5-bb9a-4f31-9f04-143da662eb04
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,912
supabase-export-v2
7e31169d78836a2e
If *spec_set* is ``True`` then attempting to set attributes that don't exist on the spec object will raise an :exc:`AttributeError`. If a class is used as a spec then the return value of the mock (the instance of the class) will have the same spec. You can use a class as the spec for an instance object by passing ``i...
trusted_official_docs
CPython Docs
If *spec_set* is ``True`` then attempting to set attributes that don't exist on the spec object will raise an :exc:`AttributeError`. If a class is used as a spec then the return value of the mock (the instance of the class) will have the same spec. You can use a class as the spec for an instance object by passing ``i...
If *spec_set* is ``True`` then attempting to set attributes that don't exist on the spec object will raise an :exc:`AttributeError`. If a class is used as a spec then the return value of the mock (the instance of the class) will have the same spec. You can use a class as the spec for an instance object by passing ``i...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a1342efa-9683-472b-bf61-e3ac5b126a6c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,801
supabase-export-v2
5a41686e18eaf827
methods. These make it simpler to do patching in ``setUp`` methods or where you want to do multiple patches without nesting decorators or with statements. To use them call :func:`patch`, :func:`patch.object` or :func:`patch.dict` as normal and keep a reference to the returned ``patcher`` object. You can then call :meth...
trusted_official_docs
CPython Docs
methods. These make it simpler to do patching in ``setUp`` methods or where you want to do multiple patches without nesting decorators or with statements. To use them call :func:`patch`, :func:`patch.object` or :func:`patch.dict` as normal and keep a reference to the returned ``patcher`` object. You can then call :meth...
methods. These make it simpler to do patching in ``setUp`` methods or where you want to do multiple patches without nesting decorators or with statements. To use them call :func:`patch`, :func:`patch.object` or :func:`patch.dict` as normal and keep a reference to the returned ``patcher`` object. You can then call :meth...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a249de66-a132-41a6-b94c-30624cae4139
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,775
supabase-export-v2
763cb5faa79ef31a
When used as a class decorator :func:`patch.dict` honours ``patch.TEST_PREFIX`` (default to ``'test'``) for choosing which methods to wrap: >>> import os >>> import unittest >>> from unittest.mock import patch >>> @patch.dict('os.environ', {'newkey': 'newvalue'}) ... class TestSample(unittest.TestCase): ... def te...
trusted_official_docs
CPython Docs
When used as a class decorator :func:`patch.dict` honours ``patch.TEST_PREFIX`` (default to ``'test'``) for choosing which methods to wrap: >>> import os >>> import unittest >>> from unittest.mock import patch >>> @patch.dict('os.environ', {'newkey': 'newvalue'}) ... class TestSample(unittest.TestCase): ... def te...
When used as a class decorator :func:`patch.dict` honours ``patch.TEST_PREFIX`` (default to ``'test'``) for choosing which methods to wrap: >>> import os >>> import unittest >>> from unittest.mock import patch >>> @patch.dict('os.environ', {'newkey': 'newvalue'}) ... class TestSample(unittest.TestCase): ... def te...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a3cc7fd0-549e-44cd-9790-de4532da460d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,827
supabase-export-v2
01576fe04d190f6c
names pointing to any individual object, so for patching to work you must ensure that you patch the name used by the system under test. The basic principle is that you patch where an object is *looked up*, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this.
trusted_official_docs
CPython Docs
names pointing to any individual object, so for patching to work you must ensure that you patch the name used by the system under test. The basic principle is that you patch where an object is *looked up*, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this.
names pointing to any individual object, so for patching to work you must ensure that you patch the name used by the system under test. The basic principle is that you patch where an object is *looked up*, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this.
python, official-docs, cpython, P0
Local_Trusted_Corpus
a449e8a7-de2f-4add-ad4c-e1ccf8ef6c29
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,800
supabase-export-v2
35785cf4c36a0b3e
patch methods: start and stop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All the patchers have :meth:`!start` and :meth:`!stop` methods. These make it simpler to do patching in ``setUp`` methods or where you want to do multiple patches without nesting decorators or with statements.
trusted_official_docs
CPython Docs
patch methods: start and stop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All the patchers have :meth:`!start` and :meth:`!stop` methods. These make it simpler to do patching in ``setUp`` methods or where you want to do multiple patches without nesting decorators or with statements.
patch methods: start and stop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ All the patchers have :meth:`!start` and :meth:`!stop` methods. These make it simpler to do patching in ``setUp`` methods or where you want to do multiple patches without nesting decorators or with statements.
python, official-docs, cpython, P0
Local_Trusted_Corpus
a63b339a-3d45-484c-90de-f11f99e1263b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,906
supabase-export-v2
71e63fd518e90982
>>> kall = m.call_args >>> kall.args (1, 2, 3) >>> kall.kwargs {'arg': 'one', 'arg2': 'two'} >>> kall.args is kall[0] True >>> kall.kwargs is kall[1] True >>> m = MagicMock() >>> m.foo(4, 5, 6, arg='two', arg2='three') <MagicMock name='mock.foo()' id='...'> >>> kall = m.mock_calls[0] >>> name, args, kwargs = kall ...
trusted_official_docs
CPython Docs
>>> kall = m.call_args >>> kall.args (1, 2, 3) >>> kall.kwargs {'arg': 'one', 'arg2': 'two'} >>> kall.args is kall[0] True >>> kall.kwargs is kall[1] True >>> m = MagicMock() >>> m.foo(4, 5, 6, arg='two', arg2='three') <MagicMock name='mock.foo()' id='...'> >>> kall = m.mock_calls[0] >>> name, args, kwargs = kall ...
>>> kall = m.call_args >>> kall.args (1, 2, 3) >>> kall.kwargs {'arg': 'one', 'arg2': 'two'} >>> kall.args is kall[0] True >>> kall.kwargs is kall[1] True >>> m = MagicMock() >>> m.foo(4, 5, 6, arg='two', arg2='three') <MagicMock name='mock.foo()' id='...'> >>> kall = m.mock_calls[0] >>> name, args, kwargs = kall ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
a7aa691b-cc26-4dc5-9dbc-bd1066563a0d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,841
supabase-export-v2
d3027c05fdd2d431
Mocking Magic Methods ~~~~~~~~~~~~~~~~~~~~~ :class:`Mock` supports mocking the Python protocol methods, also known as :term:`"magic methods" <magic method>`. This allows mock objects to replace containers or other objects that implement Python protocols.
trusted_official_docs
CPython Docs
Mocking Magic Methods ~~~~~~~~~~~~~~~~~~~~~ :class:`Mock` supports mocking the Python protocol methods, also known as :term:`"magic methods" <magic method>`. This allows mock objects to replace containers or other objects that implement Python protocols.
Mocking Magic Methods ~~~~~~~~~~~~~~~~~~~~~ :class:`Mock` supports mocking the Python protocol methods, also known as :term:`"magic methods" <magic method>`. This allows mock objects to replace containers or other objects that implement Python protocols.
python, official-docs, cpython, P0
Local_Trusted_Corpus
a8a6783d-f009-4c75-83ce-9d9d8b0dfbe9
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,434
supabase-export-v2
badc80e99e9635cd
is designed for use with :mod:`unittest` and is based on the 'action -> assertion' pattern instead of 'record -> replay' used by many mocking frameworks. There is a backport of :mod:`!unittest.mock` for earlier versions of Python, available as :pypi:`mock` on PyPI.
trusted_official_docs
CPython Docs
is designed for use with :mod:`unittest` and is based on the 'action -> assertion' pattern instead of 'record -> replay' used by many mocking frameworks. There is a backport of :mod:`!unittest.mock` for earlier versions of Python, available as :pypi:`mock` on PyPI.
is designed for use with :mod:`unittest` and is based on the 'action -> assertion' pattern instead of 'record -> replay' used by many mocking frameworks. There is a backport of :mod:`!unittest.mock` for earlier versions of Python, available as :pypi:`mock` on PyPI.
python, official-docs, cpython, P0
Local_Trusted_Corpus
a988f82a-157c-48a5-92f7-45edb7e7c4d7
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,529
supabase-export-v2
2e5bdf20fd5d80df
.. method:: attach_mock(mock, attribute) Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the :attr:`method_calls` and :attr:`mock_calls` attributes of this one.
trusted_official_docs
CPython Docs
.. method:: attach_mock(mock, attribute) Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the :attr:`method_calls` and :attr:`mock_calls` attributes of this one.
.. method:: attach_mock(mock, attribute) Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the :attr:`method_calls` and :attr:`mock_calls` attributes of this one.
python, official-docs, cpython, P0
Local_Trusted_Corpus
aa0c68af-0f02-4213-a74c-82546be8181f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,779
supabase-export-v2
1de45198d677ca14
delete keys of foo (or patched_foo, it's the same dict) ... patched_foo['spam'] = 'eggs' ... >>> assert foo == {} >>> assert patched_foo == {} >>> import os >>> with patch.dict('os.environ', {'newkey': 'newvalue'}): ... print(os.environ['newkey']) ... newvalue >>> assert 'newkey' not in os.environ
trusted_official_docs
CPython Docs
delete keys of foo (or patched_foo, it's the same dict) ... patched_foo['spam'] = 'eggs' ... >>> assert foo == {} >>> assert patched_foo == {} >>> import os >>> with patch.dict('os.environ', {'newkey': 'newvalue'}): ... print(os.environ['newkey']) ... newvalue >>> assert 'newkey' not in os.environ
delete keys of foo (or patched_foo, it's the same dict) ... patched_foo['spam'] = 'eggs' ... >>> assert foo == {} >>> assert patched_foo == {} >>> import os >>> with patch.dict('os.environ', {'newkey': 'newvalue'}): ... print(os.environ['newkey']) ... newvalue >>> assert 'newkey' not in os.environ
python, official-docs, cpython, P0
Local_Trusted_Corpus
aa247646-db52-414d-8ec8-7be7c1cfc2a2
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,967
supabase-export-v2
682885049a5e0a68
>>> req = request.Request() Traceback (most recent call last): ... TypeError: <lambda>() takes at least 2 arguments (1 given) The spec also applies to instantiated classes (i.e. the return value of specced mocks)::
trusted_official_docs
CPython Docs
>>> req = request.Request() Traceback (most recent call last): ... TypeError: <lambda>() takes at least 2 arguments (1 given) The spec also applies to instantiated classes (i.e. the return value of specced mocks)::
>>> req = request.Request() Traceback (most recent call last): ... TypeError: <lambda>() takes at least 2 arguments (1 given) The spec also applies to instantiated classes (i.e. the return value of specced mocks)::
python, official-docs, cpython, P0
Local_Trusted_Corpus
aa3dd62e-15c2-4f2e-8c3e-25fd6fa6ad36
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
27,008
supabase-export-v2
556900cdc92c1584
instance of this mock will return the real instance of the class. The positional arguments, if any, required by the wrapped object must be passed. >>> order_mock_instance = order_mock() >>> isinstance(order_mock_instance, Order) True >>> order_mock_instance.get_value() 'third'
trusted_official_docs
CPython Docs
instance of this mock will return the real instance of the class. The positional arguments, if any, required by the wrapped object must be passed. >>> order_mock_instance = order_mock() >>> isinstance(order_mock_instance, Order) True >>> order_mock_instance.get_value() 'third'
instance of this mock will return the real instance of the class. The positional arguments, if any, required by the wrapped object must be passed. >>> order_mock_instance = order_mock() >>> isinstance(order_mock_instance, Order) True >>> order_mock_instance.get_value() 'third'
python, official-docs, cpython, P0
Local_Trusted_Corpus
ab45688a-85a6-4a40-9e13-9b1cd7b61d58
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,515
supabase-export-v2
939e9a7f39e6327e
>>> mock = Mock(return_value=None) >>> mock('hello') >>> mock.called True >>> mock.reset_mock() >>> mock.called False This can be useful where you want to make a series of assertions that reuse the same object.
trusted_official_docs
CPython Docs
>>> mock = Mock(return_value=None) >>> mock('hello') >>> mock.called True >>> mock.reset_mock() >>> mock.called False This can be useful where you want to make a series of assertions that reuse the same object.
>>> mock = Mock(return_value=None) >>> mock('hello') >>> mock.called True >>> mock.reset_mock() >>> mock.called False This can be useful where you want to make a series of assertions that reuse the same object.
python, official-docs, cpython, P0
Local_Trusted_Corpus
abd040e0-4413-4c55-bdcc-ef7cde321563
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,478
supabase-export-v2
7f14a3df74d51f1b
* *return_value*: The value returned when the mock is called. By default this is a new Mock (created on first access). See the :attr:`return_value` attribute. * *unsafe*: By default, accessing any attribute whose name starts with *assert*, *assret*, *asert*, *aseert* or *assrt* will raise an :exc:`AttributeError`. Pa...
trusted_official_docs
CPython Docs
* *return_value*: The value returned when the mock is called. By default this is a new Mock (created on first access). See the :attr:`return_value` attribute. * *unsafe*: By default, accessing any attribute whose name starts with *assert*, *assret*, *asert*, *aseert* or *assrt* will raise an :exc:`AttributeError`. Pa...
* *return_value*: The value returned when the mock is called. By default this is a new Mock (created on first access). See the :attr:`return_value` attribute. * *unsafe*: By default, accessing any attribute whose name starts with *assert*, *assret*, *asert*, *aseert* or *assrt* will raise an :exc:`AttributeError`. Pa...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ac041140-15f1-427a-925e-86d1cd2a58fc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,832
supabase-export-v2
36678dcdca0b514a
have no effect on our test; module b already has a reference to the *real* ``SomeClass`` and it looks like our patching had no effect. The key is to patch out ``SomeClass`` where it is used (or where it is looked up). In this case ``some_function`` will actually look up ``SomeClass`` in module b, where we have imported...
trusted_official_docs
CPython Docs
have no effect on our test; module b already has a reference to the *real* ``SomeClass`` and it looks like our patching had no effect. The key is to patch out ``SomeClass`` where it is used (or where it is looked up). In this case ``some_function`` will actually look up ``SomeClass`` in module b, where we have imported...
have no effect on our test; module b already has a reference to the *real* ``SomeClass`` and it looks like our patching had no effect. The key is to patch out ``SomeClass`` where it is used (or where it is looked up). In this case ``some_function`` will actually look up ``SomeClass`` in module b, where we have imported...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ac19d5a3-6bde-4263-b824-b3eaa0e5d1e6
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,592
supabase-export-v2
5c6af2bf5aeb1dd9
a :attr:`!spec`, :attr:`!__class__` returns the spec class instead. This allows mock objects to pass :func:`isinstance` tests for the object they are replacing / masquerading as: >>> mock = Mock(spec=3) >>> isinstance(mock, int) True
trusted_official_docs
CPython Docs
a :attr:`!spec`, :attr:`!__class__` returns the spec class instead. This allows mock objects to pass :func:`isinstance` tests for the object they are replacing / masquerading as: >>> mock = Mock(spec=3) >>> isinstance(mock, int) True
a :attr:`!spec`, :attr:`!__class__` returns the spec class instead. This allows mock objects to pass :func:`isinstance` tests for the object they are replacing / masquerading as: >>> mock = Mock(spec=3) >>> isinstance(mock, int) True
python, official-docs, cpython, P0
Local_Trusted_Corpus
ac988ddf-fa69-4451-be2e-6c44213afc1b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,749
supabase-export-v2
61e50c7f0f8aadba
test(): ... assert sys.non_existing_attribute == 42 ... >>> test() Traceback (most recent call last): ... AttributeError: <module 'sys' (built-in)> does not have the attribute 'non_existing_attribute' but adding ``create=True`` in the call to :func:`patch` will make the previous example work as expected::
trusted_official_docs
CPython Docs
test(): ... assert sys.non_existing_attribute == 42 ... >>> test() Traceback (most recent call last): ... AttributeError: <module 'sys' (built-in)> does not have the attribute 'non_existing_attribute' but adding ``create=True`` in the call to :func:`patch` will make the previous example work as expected::
test(): ... assert sys.non_existing_attribute == 42 ... >>> test() Traceback (most recent call last): ... AttributeError: <module 'sys' (built-in)> does not have the attribute 'non_existing_attribute' but adding ``create=True`` in the call to :func:`patch` will make the previous example work as expected::
python, official-docs, cpython, P0
Local_Trusted_Corpus
ad7b3c6f-79f1-48ba-84d4-5d0f778bc089
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,710
supabase-export-v2
289af6569c96ca4f
patch('__main__.thing1', return_value=None) as child1: ... with patch('__main__.thing2', return_value=None) as child2: ... parent.attach_mock(child1, 'child1') ... parent.attach_mock(child2, 'child2') ... child1('one') ... child2('two') ... >>> parent.mock_calls [call.child1('one'), call.child2('two')] .. [#] The only ...
trusted_official_docs
CPython Docs
patch('__main__.thing1', return_value=None) as child1: ... with patch('__main__.thing2', return_value=None) as child2: ... parent.attach_mock(child1, 'child1') ... parent.attach_mock(child2, 'child2') ... child1('one') ... child2('two') ... >>> parent.mock_calls [call.child1('one'), call.child2('two')] .. [#] The only ...
patch('__main__.thing1', return_value=None) as child1: ... with patch('__main__.thing2', return_value=None) as child2: ... parent.attach_mock(child1, 'child1') ... parent.attach_mock(child2, 'child2') ... child1('one') ... child2('two') ... >>> parent.mock_calls [call.child1('one'), call.child2('two')] .. [#] The only ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
adcd9100-b784-4722-9cfd-7309c795db7d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,573
supabase-export-v2
b42ae44eabf774bb
{} >>> mock(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args call(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args.args (3, 4, 5) >>> mock.call_args.kwargs {'key': 'fish', 'next': 'w00t!'} :attr:`call_args`, along with members of the lists :attr:`call_args_list`, :attr:`method_calls` and :attr:`mock_calls` a...
trusted_official_docs
CPython Docs
{} >>> mock(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args call(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args.args (3, 4, 5) >>> mock.call_args.kwargs {'key': 'fish', 'next': 'w00t!'} :attr:`call_args`, along with members of the lists :attr:`call_args_list`, :attr:`method_calls` and :attr:`mock_calls` a...
{} >>> mock(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args call(3, 4, 5, key='fish', next='w00t!') >>> mock.call_args.args (3, 4, 5) >>> mock.call_args.kwargs {'key': 'fish', 'next': 'w00t!'} :attr:`call_args`, along with members of the lists :attr:`call_args_list`, :attr:`method_calls` and :attr:`mock_calls` a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ae0c73f6-17bf-4e86-8316-3b1d614ecd26
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,776
supabase-export-v2
45a61949f79fa034
>>> import os >>> import unittest >>> from unittest.mock import patch >>> @patch.dict('os.environ', {'newkey': 'newvalue'}) ... class TestSample(unittest.TestCase): ... def test_sample(self): ... self.assertEqual(os.environ['newkey'], 'newvalue') If you want to use a different prefix for your test, you can inform the p...
trusted_official_docs
CPython Docs
>>> import os >>> import unittest >>> from unittest.mock import patch >>> @patch.dict('os.environ', {'newkey': 'newvalue'}) ... class TestSample(unittest.TestCase): ... def test_sample(self): ... self.assertEqual(os.environ['newkey'], 'newvalue') If you want to use a different prefix for your test, you can inform the p...
>>> import os >>> import unittest >>> from unittest.mock import patch >>> @patch.dict('os.environ', {'newkey': 'newvalue'}) ... class TestSample(unittest.TestCase): ... def test_sample(self): ... self.assertEqual(os.environ['newkey'], 'newvalue') If you want to use a different prefix for your test, you can inform the p...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ae25c9d1-b769-45a6-b411-f7496f616dc6
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,685
supabase-export-v2
d018c401a0cc009d
(a new mock), or any set return value, then there are two ways of doing this. Either return :attr:`~Mock.return_value` from inside :attr:`~Mock.side_effect`, or return :data:`DEFAULT`: >>> m = MagicMock() >>> def side_effect(*args, **kwargs): ... return m.return_value ... >>> m.side_effect = side_effect >>> m.retur...
trusted_official_docs
CPython Docs
(a new mock), or any set return value, then there are two ways of doing this. Either return :attr:`~Mock.return_value` from inside :attr:`~Mock.side_effect`, or return :data:`DEFAULT`: >>> m = MagicMock() >>> def side_effect(*args, **kwargs): ... return m.return_value ... >>> m.side_effect = side_effect >>> m.retur...
(a new mock), or any set return value, then there are two ways of doing this. Either return :attr:`~Mock.return_value` from inside :attr:`~Mock.side_effect`, or return :data:`DEFAULT`: >>> m = MagicMock() >>> def side_effect(*args, **kwargs): ... return m.return_value ... >>> m.side_effect = side_effect >>> m.retur...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ae444b74-9299-41b4-88af-861fc6c6ee72
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,603
supabase-export-v2
ee29c11b44f38f99
way, using dotted notation. As you can't use dotted names directly in a call you have to create a dictionary and unpack it using ``**``: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock = Mock(some_attribute='eggs', **attrs) >>> mock.some_attribute 'eggs' >>> mock.method() 3 >>> mock...
trusted_official_docs
CPython Docs
way, using dotted notation. As you can't use dotted names directly in a call you have to create a dictionary and unpack it using ``**``: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock = Mock(some_attribute='eggs', **attrs) >>> mock.some_attribute 'eggs' >>> mock.method() 3 >>> mock...
way, using dotted notation. As you can't use dotted names directly in a call you have to create a dictionary and unpack it using ``**``: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock = Mock(some_attribute='eggs', **attrs) >>> mock.some_attribute 'eggs' >>> mock.method() 3 >>> mock...
python, official-docs, cpython, P0
Local_Trusted_Corpus
aea4fd87-e760-4ed6-b981-50c41b48733b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,716
supabase-export-v2
a6e69b1a3a6079f0
.. function:: patch(target, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) :func:`patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the *target* is patched with a *new* object. When the functi...
trusted_official_docs
CPython Docs
.. function:: patch(target, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) :func:`patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the *target* is patched with a *new* object. When the functi...
.. function:: patch(target, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) :func:`patch` acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the *target* is patched with a *new* object. When the functi...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b073dd09-891f-41da-b99f-0e7e68a2104f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,474
supabase-export-v2
60f9ca067b632b05
called with the same arguments as the mock, and unless it returns :data:`DEFAULT`, the return value of this function is used as the return value. Alternatively *side_effect* can be an exception class or instance. In this case the exception will be raised when the mock is called.
trusted_official_docs
CPython Docs
called with the same arguments as the mock, and unless it returns :data:`DEFAULT`, the return value of this function is used as the return value. Alternatively *side_effect* can be an exception class or instance. In this case the exception will be raised when the mock is called.
called with the same arguments as the mock, and unless it returns :data:`DEFAULT`, the return value of this function is used as the return value. Alternatively *side_effect* can be an exception class or instance. In this case the exception will be raised when the mock is called.
python, official-docs, cpython, P0
Local_Trusted_Corpus
b0ceac38-47d4-489b-ae34-1f08d7366a8c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,852
supabase-export-v2
2a03a7d2a40973ae
use the *spec* keyword argument to create a mock then attempting to set a magic method that isn't in the spec will raise an :exc:`AttributeError`. The full list of supported magic methods is:
trusted_official_docs
CPython Docs
use the *spec* keyword argument to create a mock then attempting to set a magic method that isn't in the spec will raise an :exc:`AttributeError`. The full list of supported magic methods is:
use the *spec* keyword argument to create a mock then attempting to set a magic method that isn't in the spec will raise an :exc:`AttributeError`. The full list of supported magic methods is:
python, official-docs, cpython, P0
Local_Trusted_Corpus
b3527477-a693-40e4-a0ab-0f1dca47fb37
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,904
supabase-export-v2
852e4efb8f7e3fc6
of (positional args, keyword args) whereas the ``call`` objects in :attr:`Mock.mock_calls`, along with ones you construct yourself, are three-tuples of (name, positional args, keyword args). You can use their "tupleness" to pull out the individual arguments for more complex introspection and assertions. The positional ...
trusted_official_docs
CPython Docs
of (positional args, keyword args) whereas the ``call`` objects in :attr:`Mock.mock_calls`, along with ones you construct yourself, are three-tuples of (name, positional args, keyword args). You can use their "tupleness" to pull out the individual arguments for more complex introspection and assertions. The positional ...
of (positional args, keyword args) whereas the ``call`` objects in :attr:`Mock.mock_calls`, along with ones you construct yourself, are three-tuples of (name, positional args, keyword args). You can use their "tupleness" to pull out the individual arguments for more complex introspection and assertions. The positional ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b3e4cdd5-196e-4162-9866-1bdc7e6f6d33
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,679
supabase-export-v2
fb5f8fd4a92164ce
Calls made to the object will be recorded in the attributes like :attr:`~Mock.call_args` and :attr:`~Mock.call_args_list`. If :attr:`~Mock.side_effect` is set then it will be called after the call has been recorded, so if :attr:`!side_effect` raises an exception the call is still recorded.
trusted_official_docs
CPython Docs
Calls made to the object will be recorded in the attributes like :attr:`~Mock.call_args` and :attr:`~Mock.call_args_list`. If :attr:`~Mock.side_effect` is set then it will be called after the call has been recorded, so if :attr:`!side_effect` raises an exception the call is still recorded.
Calls made to the object will be recorded in the attributes like :attr:`~Mock.call_args` and :attr:`~Mock.call_args_list`. If :attr:`~Mock.side_effect` is set then it will be called after the call has been recorded, so if :attr:`!side_effect` raises an exception the call is still recorded.
python, official-docs, cpython, P0
Local_Trusted_Corpus
b5ccf9e0-1820-4a4b-99fd-9831004c747d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,566
supabase-export-v2
b6e7b3768c70b370
>>> mock = Mock(return_value=3) >>> def side_effect(*args, **kwargs): ... return DEFAULT ... >>> mock.side_effect = side_effect >>> mock() 3 :attr:`side_effect` can be set in the constructor. Here's an example that adds one to the value the mock is called with and returns it:
trusted_official_docs
CPython Docs
>>> mock = Mock(return_value=3) >>> def side_effect(*args, **kwargs): ... return DEFAULT ... >>> mock.side_effect = side_effect >>> mock() 3 :attr:`side_effect` can be set in the constructor. Here's an example that adds one to the value the mock is called with and returns it:
>>> mock = Mock(return_value=3) >>> def side_effect(*args, **kwargs): ... return DEFAULT ... >>> mock.side_effect = side_effect >>> mock() 3 :attr:`side_effect` can be set in the constructor. Here's an example that adds one to the value the mock is called with and returns it:
python, official-docs, cpython, P0
Local_Trusted_Corpus
b5eba488-4020-46c1-b77b-8ce297ac1348
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,602
supabase-export-v2
4011953809fcb01c
>>> m = MagicMock(attribute=3, other='fish') >>> m.attribute 3 >>> m.other 'fish' The return value and side effect of child mocks can be set in the same way, using dotted notation. As you can't use dotted names directly in a call you have to create a dictionary and unpack it using ``**``:
trusted_official_docs
CPython Docs
>>> m = MagicMock(attribute=3, other='fish') >>> m.attribute 3 >>> m.other 'fish' The return value and side effect of child mocks can be set in the same way, using dotted notation. As you can't use dotted names directly in a call you have to create a dictionary and unpack it using ``**``:
>>> m = MagicMock(attribute=3, other='fish') >>> m.attribute 3 >>> m.other 'fish' The return value and side effect of child mocks can be set in the same way, using dotted notation. As you can't use dotted names directly in a call you have to create a dictionary and unpack it using ``**``:
python, official-docs, cpython, P0
Local_Trusted_Corpus
b7886686-e826-4219-8a51-b39f95377546
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
27,001
supabase-export-v2
11c1e52d59465970
of :attr:`~Mock.side_effect`, if you reassign its value back to ``None``, the order of precedence will be checked between :attr:`~Mock.return_value` and the wrapped object, ignoring :attr:`~Mock.side_effect`. >>> order_mock.get_value.side_effect = None >>> order_mock.get_value() 'second'
trusted_official_docs
CPython Docs
of :attr:`~Mock.side_effect`, if you reassign its value back to ``None``, the order of precedence will be checked between :attr:`~Mock.return_value` and the wrapped object, ignoring :attr:`~Mock.side_effect`. >>> order_mock.get_value.side_effect = None >>> order_mock.get_value() 'second'
of :attr:`~Mock.side_effect`, if you reassign its value back to ``None``, the order of precedence will be checked between :attr:`~Mock.return_value` and the wrapped object, ignoring :attr:`~Mock.side_effect`. >>> order_mock.get_value.side_effect = None >>> order_mock.get_value() 'second'
python, official-docs, cpython, P0
Local_Trusted_Corpus
b801affc-5654-4f49-9be1-471a4ae1def0
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,658
supabase-export-v2
efa405ef8857f408
This is either ``None`` (if the mock hasn’t been awaited), or the arguments that the mock was last awaited with. Functions the same as :attr:`Mock.call_args`. >>> mock = AsyncMock() >>> async def main(*args): ... await mock(*args) ... >>> mock.await_args >>> asyncio.run(main('foo')) >>> mock.await_args call('foo'...
trusted_official_docs
CPython Docs
This is either ``None`` (if the mock hasn’t been awaited), or the arguments that the mock was last awaited with. Functions the same as :attr:`Mock.call_args`. >>> mock = AsyncMock() >>> async def main(*args): ... await mock(*args) ... >>> mock.await_args >>> asyncio.run(main('foo')) >>> mock.await_args call('foo'...
This is either ``None`` (if the mock hasn’t been awaited), or the arguments that the mock was last awaited with. Functions the same as :attr:`Mock.call_args`. >>> mock = AsyncMock() >>> async def main(*args): ... await mock(*args) ... >>> mock.await_args >>> asyncio.run(main('foo')) >>> mock.await_args call('foo'...
python, official-docs, cpython, P0
Local_Trusted_Corpus
b84b43ab-c6b1-4947-94f7-3d843fc76c26
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,828
supabase-export-v2
faadaf73b27d4c24
object is *looked up*, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this. Imagine we have a project that we want to test with the following structure::
trusted_official_docs
CPython Docs
object is *looked up*, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this. Imagine we have a project that we want to test with the following structure::
object is *looked up*, which is not necessarily the same place as where it is defined. A couple of examples will help to clarify this. Imagine we have a project that we want to test with the following structure::
python, official-docs, cpython, P0
Local_Trusted_Corpus
b8ee183b-ff40-4dcc-afa1-ccae95a515be
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,880
supabase-export-v2
7a541ce2a890c221
>>> mock.__iter__.return_value = iter(['a', 'b', 'c']) >>> list(mock) ['a', 'b', 'c'] >>> list(mock) [] ``MagicMock`` has all of the supported magic methods configured except for some of the obscure and obsolete ones. You can still set these up if you want.
trusted_official_docs
CPython Docs
>>> mock.__iter__.return_value = iter(['a', 'b', 'c']) >>> list(mock) ['a', 'b', 'c'] >>> list(mock) [] ``MagicMock`` has all of the supported magic methods configured except for some of the obscure and obsolete ones. You can still set these up if you want.
>>> mock.__iter__.return_value = iter(['a', 'b', 'c']) >>> list(mock) ['a', 'b', 'c'] >>> list(mock) [] ``MagicMock`` has all of the supported magic methods configured except for some of the obscure and obsolete ones. You can still set these up if you want.
python, official-docs, cpython, P0
Local_Trusted_Corpus
ba7e83b6-f318-46aa-b973-4f2bb2a89257
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,958
supabase-export-v2
cfc0832724c8ae4e
a class or instance as the :attr:`!spec` for a mock then you can only access attributes on the mock that exist on the real class: >>> from urllib import request >>> mock = Mock(spec=request.Request) >>> mock.assret_called_with # Intentional typo! Traceback (most recent call last): ... AttributeError: Mock object has...
trusted_official_docs
CPython Docs
a class or instance as the :attr:`!spec` for a mock then you can only access attributes on the mock that exist on the real class: >>> from urllib import request >>> mock = Mock(spec=request.Request) >>> mock.assret_called_with # Intentional typo! Traceback (most recent call last): ... AttributeError: Mock object has...
a class or instance as the :attr:`!spec` for a mock then you can only access attributes on the mock that exist on the real class: >>> from urllib import request >>> mock = Mock(spec=request.Request) >>> mock.assret_called_with # Intentional typo! Traceback (most recent call last): ... AttributeError: Mock object has...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ba9cb47f-5578-4e1c-9ff6-cd06b2c6500f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,927
supabase-export-v2
bdd0d2ade3241bab
.. data:: FILTER_DIR :data:`FILTER_DIR` is a module level variable that controls the way mock objects respond to :func:`dir`. The default is ``True``, which uses the filtering described below, to only show useful members. If you dislike this filtering, or need to switch it off for diagnostic purposes, then set ``mock.F...
trusted_official_docs
CPython Docs
.. data:: FILTER_DIR :data:`FILTER_DIR` is a module level variable that controls the way mock objects respond to :func:`dir`. The default is ``True``, which uses the filtering described below, to only show useful members. If you dislike this filtering, or need to switch it off for diagnostic purposes, then set ``mock.F...
.. data:: FILTER_DIR :data:`FILTER_DIR` is a module level variable that controls the way mock objects respond to :func:`dir`. The default is ``True``, which uses the filtering described below, to only show useful members. If you dislike this filtering, or need to switch it off for diagnostic purposes, then set ``mock.F...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ba9f78e3-2998-43b2-9d30-7f2fae31b7af
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,804
supabase-export-v2
a48868303018d180
patcher.start() >>> assert module.ClassName is not original >>> assert module.ClassName is new_mock >>> patcher.stop() >>> assert module.ClassName is original >>> assert module.ClassName is not new_mock A typical use case for this might be for doing multiple patches in the ``setUp`` method of a :class:`~unittest.TestCa...
trusted_official_docs
CPython Docs
patcher.start() >>> assert module.ClassName is not original >>> assert module.ClassName is new_mock >>> patcher.stop() >>> assert module.ClassName is original >>> assert module.ClassName is not new_mock A typical use case for this might be for doing multiple patches in the ``setUp`` method of a :class:`~unittest.TestCa...
patcher.start() >>> assert module.ClassName is not original >>> assert module.ClassName is new_mock >>> patcher.stop() >>> assert module.ClassName is original >>> assert module.ClassName is not new_mock A typical use case for this might be for doing multiple patches in the ``setUp`` method of a :class:`~unittest.TestCa...
python, official-docs, cpython, P0
Local_Trusted_Corpus
bb42e055-518b-47b8-8324-86a4bdde2737
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,706
supabase-export-v2
c74db2dad6c134b9
MagicMock() >>> child1 = MagicMock(return_value=None) >>> child2 = MagicMock(return_value=None) >>> parent.child1 = child1 >>> parent.child2 = child2 >>> child1(1) >>> child2(2) >>> parent.mock_calls [call.child1(1), call.child2(2)] The exception to this is if the mock has a name. This allows you to prevent the "parent...
trusted_official_docs
CPython Docs
MagicMock() >>> child1 = MagicMock(return_value=None) >>> child2 = MagicMock(return_value=None) >>> parent.child1 = child1 >>> parent.child2 = child2 >>> child1(1) >>> child2(2) >>> parent.mock_calls [call.child1(1), call.child2(2)] The exception to this is if the mock has a name. This allows you to prevent the "parent...
MagicMock() >>> child1 = MagicMock(return_value=None) >>> child2 = MagicMock(return_value=None) >>> parent.child1 = child1 >>> parent.child2 = child2 >>> child1(1) >>> child2(2) >>> parent.mock_calls [call.child1(1), call.child2(2)] The exception to this is if the mock has a name. This allows you to prevent the "parent...
python, official-docs, cpython, P0
Local_Trusted_Corpus
bca2f3ae-6b6e-4c00-8206-cce57b1e2794
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,875
supabase-export-v2
a80c7f93f8626586
:meth:`!__ne__`, are special. They do the default equality comparison on identity, using the :attr:`~Mock.side_effect` attribute, unless you change their return value to return something else:: >>> MagicMock() == 3 False >>> MagicMock() != 3 True >>> mock = MagicMock() >>> mock.__eq__.return_value = True >>> mock...
trusted_official_docs
CPython Docs
:meth:`!__ne__`, are special. They do the default equality comparison on identity, using the :attr:`~Mock.side_effect` attribute, unless you change their return value to return something else:: >>> MagicMock() == 3 False >>> MagicMock() != 3 True >>> mock = MagicMock() >>> mock.__eq__.return_value = True >>> mock...
:meth:`!__ne__`, are special. They do the default equality comparison on identity, using the :attr:`~Mock.side_effect` attribute, unless you change their return value to return something else:: >>> MagicMock() == 3 False >>> MagicMock() != 3 True >>> mock = MagicMock() >>> mock.__eq__.return_value = True >>> mock...
python, official-docs, cpython, P0
Local_Trusted_Corpus
bcff264e-ab67-4a18-b3dc-ff773f70c9e8
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,737
supabase-export-v2
4c2f42e094d40d27
... >>> with patch('__main__.Class') as MockClass: ... instance = MockClass.return_value ... instance.method.return_value = 'foo' ... assert Class() is instance ... assert Class().method() == 'foo' ... If you use *spec* or *spec_set* and :func:`patch` is replacing a *class*, then the return value of the created mock wi...
trusted_official_docs
CPython Docs
... >>> with patch('__main__.Class') as MockClass: ... instance = MockClass.return_value ... instance.method.return_value = 'foo' ... assert Class() is instance ... assert Class().method() == 'foo' ... If you use *spec* or *spec_set* and :func:`patch` is replacing a *class*, then the return value of the created mock wi...
... >>> with patch('__main__.Class') as MockClass: ... instance = MockClass.return_value ... instance.method.return_value = 'foo' ... assert Class() is instance ... assert Class().method() == 'foo' ... If you use *spec* or *spec_set* and :func:`patch` is replacing a *class*, then the return value of the created mock wi...
python, official-docs, cpython, P0
Local_Trusted_Corpus
be40d459-4240-43e1-8a65-b8fbd6f65fb9
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,480
supabase-export-v2
47b0aad738d160cf
.. versionadded:: 3.5 * *wraps*: Item for the mock object to wrap. If *wraps* is not ``None`` then calling the Mock will pass the call through to the wrapped object (returning the real result). Attribute access on the mock will return a Mock object that wraps the corresponding attribute of the wrapped object (so at...
trusted_official_docs
CPython Docs
.. versionadded:: 3.5 * *wraps*: Item for the mock object to wrap. If *wraps* is not ``None`` then calling the Mock will pass the call through to the wrapped object (returning the real result). Attribute access on the mock will return a Mock object that wraps the corresponding attribute of the wrapped object (so at...
.. versionadded:: 3.5 * *wraps*: Item for the mock object to wrap. If *wraps* is not ``None`` then calling the Mock will pass the call through to the wrapped object (returning the real result). Attribute access on the mock will return a Mock object that wraps the corresponding attribute of the wrapped object (so at...
python, official-docs, cpython, P0
Local_Trusted_Corpus
bf257ddd-3040-4ab9-87a2-aed8dca27db5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,788
supabase-export-v2
ecffcccd215febd3
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use :data:`DEFAULT` as the value if you want :func:`patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when :func:`patch.multiple` is used as a ...
trusted_official_docs
CPython Docs
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use :data:`DEFAULT` as the value if you want :func:`patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when :func:`patch.multiple` is used as a ...
with patch.multiple(settings, FIRST_PATCH='one', SECOND_PATCH='two'): ... Use :data:`DEFAULT` as the value if you want :func:`patch.multiple` to create mocks for you. In this case the created mocks are passed into a decorated function by keyword, and a dictionary is returned when :func:`patch.multiple` is used as a ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c09eca74-5c1c-42d6-86ea-f0a6d34f414b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,969
supabase-export-v2
0d15a15b7e978a26
>>> req = request.Request('foo') >>> req <NonCallableMagicMock name='request.Request()' spec='Request' id='...'> :class:`!Request` objects are not callable, so the return value of instantiating our mocked out :class:`!request.Request` is a non-callable mock. With the spec in place any typos in our asserts will raise th...
trusted_official_docs
CPython Docs
>>> req = request.Request('foo') >>> req <NonCallableMagicMock name='request.Request()' spec='Request' id='...'> :class:`!Request` objects are not callable, so the return value of instantiating our mocked out :class:`!request.Request` is a non-callable mock. With the spec in place any typos in our asserts will raise th...
>>> req = request.Request('foo') >>> req <NonCallableMagicMock name='request.Request()' spec='Request' id='...'> :class:`!Request` objects are not callable, so the return value of instantiating our mocked out :class:`!request.Request` is a non-callable mock. With the spec in place any typos in our asserts will raise th...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c227c7f1-aa55-464a-8fb4-aada2be4b7b5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,730
supabase-export-v2
82c5af4e71a69f87
:func:`patch` takes arbitrary keyword arguments. These will be passed to :class:`AsyncMock` if the patched object is asynchronous, to :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are available for alternate use-cases.
trusted_official_docs
CPython Docs
:func:`patch` takes arbitrary keyword arguments. These will be passed to :class:`AsyncMock` if the patched object is asynchronous, to :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are available for alternate use-cases.
:func:`patch` takes arbitrary keyword arguments. These will be passed to :class:`AsyncMock` if the patched object is asynchronous, to :class:`MagicMock` otherwise or to *new_callable* if specified. ``patch.dict(...)``, ``patch.multiple(...)`` and ``patch.object(...)`` are available for alternate use-cases.
python, official-docs, cpython, P0
Local_Trusted_Corpus
c3bda270-6b60-4499-8d43-6cceb5cf9462
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,760
supabase-export-v2
3954aebe59d740fa
argument form you omit the replacement object, and a mock is created for you and passed in as an extra argument to the decorated function: >>> @patch.object(SomeClass, 'class_method') ... def test(mock_method): ... SomeClass.class_method(3) ... mock_method.assert_called_with(3) ... >>> test()
trusted_official_docs
CPython Docs
argument form you omit the replacement object, and a mock is created for you and passed in as an extra argument to the decorated function: >>> @patch.object(SomeClass, 'class_method') ... def test(mock_method): ... SomeClass.class_method(3) ... mock_method.assert_called_with(3) ... >>> test()
argument form you omit the replacement object, and a mock is created for you and passed in as an extra argument to the decorated function: >>> @patch.object(SomeClass, 'class_method') ... def test(mock_method): ... SomeClass.class_method(3) ... mock_method.assert_called_with(3) ... >>> test()
python, official-docs, cpython, P0
Local_Trusted_Corpus
c43ac7ee-8bfa-4d5b-a4a4-e10f89050605
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,445
supabase-export-v2
a4b70716b9a2d5c5
its specification from another object. Attempting to access attributes or methods on the mock that don't exist on the spec will fail with an :exc:`AttributeError`. The :func:`patch` decorator / context manager makes it easy to mock classes or objects in a module under test. The object you specify will be replaced with ...
trusted_official_docs
CPython Docs
its specification from another object. Attempting to access attributes or methods on the mock that don't exist on the spec will fail with an :exc:`AttributeError`. The :func:`patch` decorator / context manager makes it easy to mock classes or objects in a module under test. The object you specify will be replaced with ...
its specification from another object. Attempting to access attributes or methods on the mock that don't exist on the spec will fail with an :exc:`AttributeError`. The :func:`patch` decorator / context manager makes it easy to mock classes or objects in a module under test. The object you specify will be replaced with ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c47c040d-8898-4c1c-b7d9-27e4f568c62c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,457
supabase-export-v2
e9186193b7531668
appropriately. The :class:`MagicMock` class is just a Mock variant that has all of the magic methods pre-created for you (well, all the useful ones anyway). The following is an example of using magic methods with the ordinary Mock class:
trusted_official_docs
CPython Docs
appropriately. The :class:`MagicMock` class is just a Mock variant that has all of the magic methods pre-created for you (well, all the useful ones anyway). The following is an example of using magic methods with the ordinary Mock class:
appropriately. The :class:`MagicMock` class is just a Mock variant that has all of the magic methods pre-created for you (well, all the useful ones anyway). The following is an example of using magic methods with the ordinary Mock class:
python, official-docs, cpython, P0
Local_Trusted_Corpus
c49f3977-2cba-45d8-96f3-6e17bd98ed01
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,979
supabase-export-v2
e5fe512054ab8d65
>>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a = 33 ... There is a more aggressive version of both *spec* and *autospec* that *does* prevent you setting non-existent attributes. This is useful if you want to ensure your code only *sets* valid attributes too, but obviously it pr...
trusted_official_docs
CPython Docs
>>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a = 33 ... There is a more aggressive version of both *spec* and *autospec* that *does* prevent you setting non-existent attributes. This is useful if you want to ensure your code only *sets* valid attributes too, but obviously it pr...
>>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a = 33 ... There is a more aggressive version of both *spec* and *autospec* that *does* prevent you setting non-existent attributes. This is useful if you want to ensure your code only *sets* valid attributes too, but obviously it pr...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c4a3ac65-3f13-404b-9c44-2fe4bfb02220
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,938
supabase-export-v2
b4ea5f1338507e88
A helper function to create a mock to replace the use of :func:`open`. It works for :func:`open` called directly or used as a context manager. The *mock* argument is the mock object to configure. If ``None`` (the default) then a :class:`MagicMock` will be created for you, with the API limited to methods or attributes...
trusted_official_docs
CPython Docs
A helper function to create a mock to replace the use of :func:`open`. It works for :func:`open` called directly or used as a context manager. The *mock* argument is the mock object to configure. If ``None`` (the default) then a :class:`MagicMock` will be created for you, with the API limited to methods or attributes...
A helper function to create a mock to replace the use of :func:`open`. It works for :func:`open` called directly or used as a context manager. The *mock* argument is the mock object to configure. If ``None`` (the default) then a :class:`MagicMock` will be created for you, with the API limited to methods or attributes...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c4fa5a62-3d0e-49aa-942d-e6249f1bbd12
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,448
supabase-export-v2
3df48a1f77fef95c
.. note:: When you nest patch decorators the mocks are passed in to the decorated function in the same order they applied (the normal *Python* order that decorators are applied). This means from the bottom up, so in the example above the mock for ``module.ClassName1`` is passed in first.
trusted_official_docs
CPython Docs
.. note:: When you nest patch decorators the mocks are passed in to the decorated function in the same order they applied (the normal *Python* order that decorators are applied). This means from the bottom up, so in the example above the mock for ``module.ClassName1`` is passed in first.
.. note:: When you nest patch decorators the mocks are passed in to the decorated function in the same order they applied (the normal *Python* order that decorators are applied). This means from the bottom up, so in the example above the mock for ``module.ClassName1`` is passed in first.
python, official-docs, cpython, P0
Local_Trusted_Corpus
c5a88e4f-2410-4352-bf31-7b04beb88a32
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,819
supabase-export-v2
bc43b2cc2f7e68c9
is possible that you want to use a different prefix for your tests. You can inform the patchers of the different prefix by setting ``patch.TEST_PREFIX``:: >>> patch.TEST_PREFIX = 'foo' >>> value = 3 >>> >>> @patch('__main__.value', 'not three') ... class Thing: ... def foo_one(self): ... print(value) ... def foo...
trusted_official_docs
CPython Docs
is possible that you want to use a different prefix for your tests. You can inform the patchers of the different prefix by setting ``patch.TEST_PREFIX``:: >>> patch.TEST_PREFIX = 'foo' >>> value = 3 >>> >>> @patch('__main__.value', 'not three') ... class Thing: ... def foo_one(self): ... print(value) ... def foo...
is possible that you want to use a different prefix for your tests. You can inform the patchers of the different prefix by setting ``patch.TEST_PREFIX``:: >>> patch.TEST_PREFIX = 'foo' >>> value = 3 >>> >>> @patch('__main__.value', 'not three') ... class Thing: ... def foo_one(self): ... print(value) ... def foo...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c7a2c58b-2196-4b59-863b-502c4c80971b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,682
supabase-export-v2
42a397969c2adc73
3)] >>> m.side_effect = KeyError('Bang!') >>> m('two', 'three', 'four') Traceback (most recent call last): ... KeyError: 'Bang!' >>> m.mock_calls [call(1, 2, 3), call('two', 'three', 'four')] If :attr:`~Mock.side_effect` is a function then whatever that function returns is what calls to the mock return. The :attr:`!sid...
trusted_official_docs
CPython Docs
3)] >>> m.side_effect = KeyError('Bang!') >>> m('two', 'three', 'four') Traceback (most recent call last): ... KeyError: 'Bang!' >>> m.mock_calls [call(1, 2, 3), call('two', 'three', 'four')] If :attr:`~Mock.side_effect` is a function then whatever that function returns is what calls to the mock return. The :attr:`!sid...
3)] >>> m.side_effect = KeyError('Bang!') >>> m('two', 'three', 'four') Traceback (most recent call last): ... KeyError: 'Bang!' >>> m.mock_calls [call(1, 2, 3), call('two', 'three', 'four')] If :attr:`~Mock.side_effect` is a function then whatever that function returns is what calls to the mock return. The :attr:`!sid...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c805be40-a34a-413b-8a6e-f8c7836b4459
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,439
supabase-export-v2
717fd7ec8e61e761
@classmethod def class_method(cls, args): return args :class:`Mock` and :class:`MagicMock` objects create all attributes and methods as you access them and store details of how they have been used. You can configure them, to specify return values or limit what attributes are available, and then make assertions about ho...
trusted_official_docs
CPython Docs
@classmethod def class_method(cls, args): return args :class:`Mock` and :class:`MagicMock` objects create all attributes and methods as you access them and store details of how they have been used. You can configure them, to specify return values or limit what attributes are available, and then make assertions about ho...
@classmethod def class_method(cls, args): return args :class:`Mock` and :class:`MagicMock` objects create all attributes and methods as you access them and store details of how they have been used. You can configure them, to specify return values or limit what attributes are available, and then make assertions about ho...
python, official-docs, cpython, P0
Local_Trusted_Corpus
c896ef1f-dcfd-4126-a188-920822cb4988
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,748
supabase-export-v2
26201793ec9f1fb4
attempting to patch a function in a module (or a method or an attribute in a class) that does not exist will fail with :exc:`AttributeError`:: >>> @patch('sys.non_existing_attribute', 42) ... def test(): ... assert sys.non_existing_attribute == 42 ... >>> test() Traceback (most recent call last): ... AttributeErro...
trusted_official_docs
CPython Docs
attempting to patch a function in a module (or a method or an attribute in a class) that does not exist will fail with :exc:`AttributeError`:: >>> @patch('sys.non_existing_attribute', 42) ... def test(): ... assert sys.non_existing_attribute == 42 ... >>> test() Traceback (most recent call last): ... AttributeErro...
attempting to patch a function in a module (or a method or an attribute in a class) that does not exist will fail with :exc:`AttributeError`:: >>> @patch('sys.non_existing_attribute', 42) ... def test(): ... assert sys.non_existing_attribute == 42 ... >>> test() Traceback (most recent call last): ... AttributeErro...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ca3984d6-b205-428f-949c-1d4c5d9c75ed
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,532
supabase-export-v2
5257712c7183cb79
Set attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call:
trusted_official_docs
CPython Docs
Set attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call:
Set attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call:
python, official-docs, cpython, P0
Local_Trusted_Corpus
ca4e3944-997d-4c14-a20d-c1fe95e26b38
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,971
supabase-export-v2
7e98f98c6d0febd2
'eggs') <MagicMock name='request.Request().add_header()' id='...'> >>> req.add_header.assret_called_with # Intentional typo! Traceback (most recent call last): ... AttributeError: Mock object has no attribute 'assret_called_with' >>> req.add_header.assert_called_with('spam', 'eggs') In many cases you will just be able ...
trusted_official_docs
CPython Docs
'eggs') <MagicMock name='request.Request().add_header()' id='...'> >>> req.add_header.assret_called_with # Intentional typo! Traceback (most recent call last): ... AttributeError: Mock object has no attribute 'assret_called_with' >>> req.add_header.assert_called_with('spam', 'eggs') In many cases you will just be able ...
'eggs') <MagicMock name='request.Request().add_header()' id='...'> >>> req.add_header.assret_called_with # Intentional typo! Traceback (most recent call last): ... AttributeError: Mock object has no attribute 'assret_called_with' >>> req.add_header.assert_called_with('spam', 'eggs') In many cases you will just be able ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
ca9bd6c1-34d6-48ce-8fdf-ff225acf9874
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,626
supabase-export-v2
2d3922476f2c82a9
them as :class:`MagicMock` (if the parent mock is :class:`AsyncMock` or :class:`MagicMock`) or :class:`Mock` (if the parent mock is :class:`Mock`). All asynchronous functions will be :class:`AsyncMock`. >>> class ExampleClass: ... def sync_foo(): ... pass ... async def async_foo(): ... pass ... >>> a_mock = AsyncM...
trusted_official_docs
CPython Docs
them as :class:`MagicMock` (if the parent mock is :class:`AsyncMock` or :class:`MagicMock`) or :class:`Mock` (if the parent mock is :class:`Mock`). All asynchronous functions will be :class:`AsyncMock`. >>> class ExampleClass: ... def sync_foo(): ... pass ... async def async_foo(): ... pass ... >>> a_mock = AsyncM...
them as :class:`MagicMock` (if the parent mock is :class:`AsyncMock` or :class:`MagicMock`) or :class:`Mock` (if the parent mock is :class:`Mock`). All asynchronous functions will be :class:`AsyncMock`. >>> class ExampleClass: ... def sync_foo(): ... pass ... async def async_foo(): ... pass ... >>> a_mock = AsyncM...
python, official-docs, cpython, P0
Local_Trusted_Corpus