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
33cca845-9cd6-4ef2-8ce1-3f3d16f872b3
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,624
supabase-export-v2
5f94966a3435e0ff
Setting the *spec* of a :class:`Mock` or :class:`MagicMock` to an async function will result in a coroutine object being returned after calling. >>> async def async_func(): pass ... >>> mock = MagicMock(async_func) >>> mock <MagicMock spec='function' id='...'> >>> mock() # doctest: +SKIP <coroutine object AsyncMoc...
trusted_official_docs
CPython Docs
Setting the *spec* of a :class:`Mock` or :class:`MagicMock` to an async function will result in a coroutine object being returned after calling. >>> async def async_func(): pass ... >>> mock = MagicMock(async_func) >>> mock <MagicMock spec='function' id='...'> >>> mock() # doctest: +SKIP <coroutine object AsyncMoc...
Setting the *spec* of a :class:`Mock` or :class:`MagicMock` to an async function will result in a coroutine object being returned after calling. >>> async def async_func(): pass ... >>> mock = MagicMock(async_func) >>> mock <MagicMock spec='function' id='...'> >>> mock() # doctest: +SKIP <coroutine object AsyncMoc...
python, official-docs, cpython, P0
Local_Trusted_Corpus
34742aee-b3a0-4370-a1ba-d1621aa6b37e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,625
supabase-export-v2
d24335175698027e
>>> async def async_func(): pass ... >>> mock = MagicMock(async_func) >>> mock <MagicMock spec='function' id='...'> >>> mock() # doctest: +SKIP <coroutine object AsyncMockMixin._mock_call at ...> Setting the *spec* of a :class:`Mock`, :class:`MagicMock`, or :class:`AsyncMock` to a class with asynchronous and synchrono...
trusted_official_docs
CPython Docs
>>> async def async_func(): pass ... >>> mock = MagicMock(async_func) >>> mock <MagicMock spec='function' id='...'> >>> mock() # doctest: +SKIP <coroutine object AsyncMockMixin._mock_call at ...> Setting the *spec* of a :class:`Mock`, :class:`MagicMock`, or :class:`AsyncMock` to a class with asynchronous and synchrono...
>>> async def async_func(): pass ... >>> mock = MagicMock(async_func) >>> mock <MagicMock spec='function' id='...'> >>> mock() # doctest: +SKIP <coroutine object AsyncMockMixin._mock_call at ...> Setting the *spec* of a :class:`Mock`, :class:`MagicMock`, or :class:`AsyncMock` to a class with asynchronous and synchrono...
python, official-docs, cpython, P0
Local_Trusted_Corpus
34fbaf82-8625-470f-9cea-00b3ae106468
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,946
supabase-export-v2
762806896e543bee
you mock out the call to :func:`open` it is the *returned object* that is used as a context manager (and has :meth:`~object.__enter__` and :meth:`~object.__exit__` called). Mocking context managers with a :class:`MagicMock` is common enough and fiddly enough that a helper function is useful. ::
trusted_official_docs
CPython Docs
you mock out the call to :func:`open` it is the *returned object* that is used as a context manager (and has :meth:`~object.__enter__` and :meth:`~object.__exit__` called). Mocking context managers with a :class:`MagicMock` is common enough and fiddly enough that a helper function is useful. ::
you mock out the call to :func:`open` it is the *returned object* that is used as a context manager (and has :meth:`~object.__enter__` and :meth:`~object.__exit__` called). Mocking context managers with a :class:`MagicMock` is common enough and fiddly enough that a helper function is useful. ::
python, official-docs, cpython, P0
Local_Trusted_Corpus
34fe4203-4ba1-42b5-b18c-95423f1b3db2
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,535
supabase-export-v2
76657f3c4dc4517a
The same thing can be achieved in the constructor call to mocks: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock = Mock(some_attribute='eggs', **attrs) >>> mock.some_attribute 'eggs' >>> mock.method() 3 >>> mock.other() Traceback (most recent call last): ... KeyError
trusted_official_docs
CPython Docs
The same thing can be achieved in the constructor call to mocks: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock = Mock(some_attribute='eggs', **attrs) >>> mock.some_attribute 'eggs' >>> mock.method() 3 >>> mock.other() Traceback (most recent call last): ... KeyError
The same thing can be achieved in the constructor call to mocks: >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock = Mock(some_attribute='eggs', **attrs) >>> mock.some_attribute 'eggs' >>> mock.method() 3 >>> mock.other() Traceback (most recent call last): ... KeyError
python, official-docs, cpython, P0
Local_Trusted_Corpus
364b5bd5-5bb3-4b82-9124-7aa9f148182c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,945
supabase-export-v2
a54a41607437d45e
with open('/some/path', 'w') as f: f.write('something') The issue is that even if you mock out the call to :func:`open` it is the *returned object* that is used as a context manager (and has :meth:`~object.__enter__` and :meth:`~object.__exit__` called).
trusted_official_docs
CPython Docs
with open('/some/path', 'w') as f: f.write('something') The issue is that even if you mock out the call to :func:`open` it is the *returned object* that is used as a context manager (and has :meth:`~object.__enter__` and :meth:`~object.__exit__` called).
with open('/some/path', 'w') as f: f.write('something') The issue is that even if you mock out the call to :func:`open` it is the *returned object* that is used as a context manager (and has :meth:`~object.__enter__` and :meth:`~object.__exit__` called).
python, official-docs, cpython, P0
Local_Trusted_Corpus
365112a3-a929-4423-85d5-4d727ae0e326
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,973
supabase-export-v2
cc7884ee1678576a
As well as using *autospec* through :func:`patch` there is a :func:`create_autospec` for creating autospecced mocks directly: >>> from urllib import request >>> mock_request = create_autospec(request) >>> mock_request.Request('foo', 'bar') <NonCallableMagicMock name='mock.Request()' spec='Request' id='...'>
trusted_official_docs
CPython Docs
As well as using *autospec* through :func:`patch` there is a :func:`create_autospec` for creating autospecced mocks directly: >>> from urllib import request >>> mock_request = create_autospec(request) >>> mock_request.Request('foo', 'bar') <NonCallableMagicMock name='mock.Request()' spec='Request' id='...'>
As well as using *autospec* through :func:`patch` there is a :func:`create_autospec` for creating autospecced mocks directly: >>> from urllib import request >>> mock_request = create_autospec(request) >>> mock_request.Request('foo', 'bar') <NonCallableMagicMock name='mock.Request()' spec='Request' id='...'>
python, official-docs, cpython, P0
Local_Trusted_Corpus
37d1c2b1-2986-45fc-af8e-289ddd89c611
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,678
supabase-export-v2
f7297b44202abcdb
time the return value is accessed (either explicitly or by calling the Mock) - but it is stored and the same one returned each time. Calls made to the object will be recorded in the attributes like :attr:`~Mock.call_args` and :attr:`~Mock.call_args_list`.
trusted_official_docs
CPython Docs
time the return value is accessed (either explicitly or by calling the Mock) - but it is stored and the same one returned each time. Calls made to the object will be recorded in the attributes like :attr:`~Mock.call_args` and :attr:`~Mock.call_args_list`.
time the return value is accessed (either explicitly or by calling the Mock) - but it is stored and the same one returned each time. Calls made to the object will be recorded in the attributes like :attr:`~Mock.call_args` and :attr:`~Mock.call_args_list`.
python, official-docs, cpython, P0
Local_Trusted_Corpus
38dc5736-98ef-4da8-8032-368c24c73394
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,613
supabase-export-v2
0d65d45f0c7837db
way mock attributes are stored you can't directly attach a :class:`PropertyMock` to a mock object. Instead you can attach it to the mock type object:: >>> m = MagicMock() >>> p = PropertyMock(return_value=3) >>> type(m).foo = p >>> m.foo 3 >>> p.assert_called_once_with()
trusted_official_docs
CPython Docs
way mock attributes are stored you can't directly attach a :class:`PropertyMock` to a mock object. Instead you can attach it to the mock type object:: >>> m = MagicMock() >>> p = PropertyMock(return_value=3) >>> type(m).foo = p >>> m.foo 3 >>> p.assert_called_once_with()
way mock attributes are stored you can't directly attach a :class:`PropertyMock` to a mock object. Instead you can attach it to the mock type object:: >>> m = MagicMock() >>> p = PropertyMock(return_value=3) >>> type(m).foo = p >>> m.foo 3 >>> p.assert_called_once_with()
python, official-docs, cpython, P0
Local_Trusted_Corpus
38ef19d9-0276-49cc-b1e9-e0ff56480783
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,888
supabase-export-v2
eb06f1300c5749f1
.. versionchanged:: 3.7 The ``sentinel`` attributes now preserve their identity when they are :mod:`copied <copy>` or :mod:`pickled <pickle>`. Sometimes when testing you need to test that a specific object is passed as an argument to another method, or returned. It can be common to create named sentinel objects to test...
trusted_official_docs
CPython Docs
.. versionchanged:: 3.7 The ``sentinel`` attributes now preserve their identity when they are :mod:`copied <copy>` or :mod:`pickled <pickle>`. Sometimes when testing you need to test that a specific object is passed as an argument to another method, or returned. It can be common to create named sentinel objects to test...
.. versionchanged:: 3.7 The ``sentinel`` attributes now preserve their identity when they are :mod:`copied <copy>` or :mod:`pickled <pickle>`. Sometimes when testing you need to test that a specific object is passed as an argument to another method, or returned. It can be common to create named sentinel objects to test...
python, official-docs, cpython, P0
Local_Trusted_Corpus
398c8dec-8763-492c-9fdc-b5cc611b082f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,918
supabase-export-v2
b42bc7ee48ff4d43
.. data:: ANY Sometimes you may need to make assertions about *some* of the arguments in a call to mock, but either not care about some of the arguments or want to pull them individually out of :attr:`~Mock.call_args` and make more complex assertions on them.
trusted_official_docs
CPython Docs
.. data:: ANY Sometimes you may need to make assertions about *some* of the arguments in a call to mock, but either not care about some of the arguments or want to pull them individually out of :attr:`~Mock.call_args` and make more complex assertions on them.
.. data:: ANY Sometimes you may need to make assertions about *some* of the arguments in a call to mock, but either not care about some of the arguments or want to pull them individually out of :attr:`~Mock.call_args` and make more complex assertions on them.
python, official-docs, cpython, P0
Local_Trusted_Corpus
39acdbbb-5364-4c19-bc75-535f3fbfbddc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,506
supabase-export-v2
c5dbbcd75b39a999
If *any_order* is true then the calls can be in any order, but they must all appear in :attr:`mock_calls`. >>> mock = Mock(return_value=None) >>> mock(1) >>> mock(2) >>> mock(3) >>> mock(4) >>> calls = [call(2), call(3)] >>> mock.assert_has_calls(calls) >>> calls = [call(4), call(2), call(3)] >>> mock.assert_ha...
trusted_official_docs
CPython Docs
If *any_order* is true then the calls can be in any order, but they must all appear in :attr:`mock_calls`. >>> mock = Mock(return_value=None) >>> mock(1) >>> mock(2) >>> mock(3) >>> mock(4) >>> calls = [call(2), call(3)] >>> mock.assert_has_calls(calls) >>> calls = [call(4), call(2), call(3)] >>> mock.assert_ha...
If *any_order* is true then the calls can be in any order, but they must all appear in :attr:`mock_calls`. >>> mock = Mock(return_value=None) >>> mock(1) >>> mock(2) >>> mock(3) >>> mock(4) >>> calls = [call(2), call(3)] >>> mock.assert_has_calls(calls) >>> calls = [call(4), call(2), call(3)] >>> mock.assert_ha...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3a0740d7-d839-4926-8968-de89477a856b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,468
supabase-export-v2
273b6a01e15220bd
:class:`Mock` object. By default :func:`patch` will create a :class:`MagicMock` for you. You can specify an alternative class of :class:`Mock` using the *new_callable* argument to :func:`patch`. .. class:: Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwar...
trusted_official_docs
CPython Docs
:class:`Mock` object. By default :func:`patch` will create a :class:`MagicMock` for you. You can specify an alternative class of :class:`Mock` using the *new_callable* argument to :func:`patch`. .. class:: Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwar...
:class:`Mock` object. By default :func:`patch` will create a :class:`MagicMock` for you. You can specify an alternative class of :class:`Mock` using the *new_callable* argument to :func:`patch`. .. class:: Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwar...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3a94fcc3-3f84-4fe6-9e6a-0e8db56fed2b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,464
supabase-export-v2
8a0ebd6a7f9b005e
.. testsetup:: import asyncio import inspect import unittest 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
trusted_official_docs
CPython Docs
.. testsetup:: import asyncio import inspect import unittest 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
.. testsetup:: import asyncio import inspect import unittest 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
python, official-docs, cpython, P0
Local_Trusted_Corpus
3b0ce3ab-7de3-4853-acc7-d0c9164bab46
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,688
supabase-export-v2
f9a2a1d62bd7e5f0
m = MagicMock(return_value=6) >>> def side_effect(*args, **kwargs): ... return 3 ... >>> m.side_effect = side_effect >>> m() 3 >>> m.side_effect = None >>> m() 6 The :attr:`~Mock.side_effect` can also be any iterable object. Repeated calls to the mock will return values from the iterable (until the iterable is exhauste...
trusted_official_docs
CPython Docs
m = MagicMock(return_value=6) >>> def side_effect(*args, **kwargs): ... return 3 ... >>> m.side_effect = side_effect >>> m() 3 >>> m.side_effect = None >>> m() 6 The :attr:`~Mock.side_effect` can also be any iterable object. Repeated calls to the mock will return values from the iterable (until the iterable is exhauste...
m = MagicMock(return_value=6) >>> def side_effect(*args, **kwargs): ... return 3 ... >>> m.side_effect = side_effect >>> m() 3 >>> m.side_effect = None >>> m() 6 The :attr:`~Mock.side_effect` can also be any iterable object. Repeated calls to the mock will return values from the iterable (until the iterable is exhauste...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3b41da51-b887-4986-ae44-5ddcb336820b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
27,000
supabase-export-v2
5b025b3a1ef4f82b
... @staticmethod ... def get_value(): ... return "third" ... >>> order_mock = Mock(spec=Order, wraps=Order) >>> order_mock.get_value.side_effect = ["first"] >>> order_mock.get_value.return_value = "second" >>> order_mock.get_value() 'first' As ``None`` is the default value of :attr:`~Mock.side_effect`, if you reassign...
trusted_official_docs
CPython Docs
... @staticmethod ... def get_value(): ... return "third" ... >>> order_mock = Mock(spec=Order, wraps=Order) >>> order_mock.get_value.side_effect = ["first"] >>> order_mock.get_value.return_value = "second" >>> order_mock.get_value() 'first' As ``None`` is the default value of :attr:`~Mock.side_effect`, if you reassign...
... @staticmethod ... def get_value(): ... return "third" ... >>> order_mock = Mock(spec=Order, wraps=Order) >>> order_mock.get_value.side_effect = ["first"] >>> order_mock.get_value.return_value = "second" >>> order_mock.get_value() 'first' As ``None`` is the default value of :attr:`~Mock.side_effect`, if you reassign...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3b929934-1db3-4c09-939a-9d6686bd3cfb
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,796
supabase-export-v2
afbb79f6740ffe92
thing=DEFAULT, other=DEFAULT) ... def test_function(mock_exit, other, thing): ... assert 'other' in repr(other) ... assert 'thing' in repr(thing) ... assert 'exit' in repr(mock_exit) ... >>> test_function() If :func:`patch.multiple` is used as a context manager, the value returned by the context manager is a dictionary...
trusted_official_docs
CPython Docs
thing=DEFAULT, other=DEFAULT) ... def test_function(mock_exit, other, thing): ... assert 'other' in repr(other) ... assert 'thing' in repr(thing) ... assert 'exit' in repr(mock_exit) ... >>> test_function() If :func:`patch.multiple` is used as a context manager, the value returned by the context manager is a dictionary...
thing=DEFAULT, other=DEFAULT) ... def test_function(mock_exit, other, thing): ... assert 'other' in repr(other) ... assert 'thing' in repr(thing) ... assert 'exit' in repr(mock_exit) ... >>> test_function() If :func:`patch.multiple` is used as a context manager, the value returned by the context manager is a dictionary...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3de136c0-5ab8-46af-a465-37ab8115bf27
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,663
supabase-export-v2
02cd73aae6c4d18d
.. class:: ThreadingMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, *, timeout=UNSET, **kwargs) A version of :class:`MagicMock` for multithreading tests. The :class:`ThreadingMock` object provides extra methods to wait for a call to be invoked, rather than a...
trusted_official_docs
CPython Docs
.. class:: ThreadingMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, *, timeout=UNSET, **kwargs) A version of :class:`MagicMock` for multithreading tests. The :class:`ThreadingMock` object provides extra methods to wait for a call to be invoked, rather than a...
.. class:: ThreadingMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, *, timeout=UNSET, **kwargs) A version of :class:`MagicMock` for multithreading tests. The :class:`ThreadingMock` object provides extra methods to wait for a call to be invoked, rather than a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3df61ab7-5e6d-4fba-b57f-ce3121021fcb
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,976
supabase-export-v2
533beceebb2f502b
and not to exist on the class at all. *autospec* can't know about any dynamically created attributes and restricts the api to visible attributes. :: >>> class Something: ... def __init__(self): ... self.a = 33 ... >>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a ... Traceba...
trusted_official_docs
CPython Docs
and not to exist on the class at all. *autospec* can't know about any dynamically created attributes and restricts the api to visible attributes. :: >>> class Something: ... def __init__(self): ... self.a = 33 ... >>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a ... Traceba...
and not to exist on the class at all. *autospec* can't know about any dynamically created attributes and restricts the api to visible attributes. :: >>> class Something: ... def __init__(self): ... self.a = 33 ... >>> with patch('__main__.Something', autospec=True): ... thing = Something() ... thing.a ... Traceba...
python, official-docs, cpython, P0
Local_Trusted_Corpus
3e4b608c-9539-4a7c-aff5-81834e0f4a92
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,742
supabase-export-v2
ce2cc60598387d15
Another use case might be to replace an object with an :class:`io.StringIO` instance:: >>> from io import StringIO >>> def foo(): ... print('Something') ... >>> @patch('sys.stdout', new_callable=StringIO) ... def test(mock_stdout): ... foo() ... assert mock_stdout.getvalue() == 'Something\n' ... >>> test()
trusted_official_docs
CPython Docs
Another use case might be to replace an object with an :class:`io.StringIO` instance:: >>> from io import StringIO >>> def foo(): ... print('Something') ... >>> @patch('sys.stdout', new_callable=StringIO) ... def test(mock_stdout): ... foo() ... assert mock_stdout.getvalue() == 'Something\n' ... >>> test()
Another use case might be to replace an object with an :class:`io.StringIO` instance:: >>> from io import StringIO >>> def foo(): ... print('Something') ... >>> @patch('sys.stdout', new_callable=StringIO) ... def test(mock_stdout): ... foo() ... assert mock_stdout.getvalue() == 'Something\n' ... >>> test()
python, official-docs, cpython, P0
Local_Trusted_Corpus
3e7092bc-1474-4310-b0f3-227a7933a9c1
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,451
supabase-export-v2
f0d82088231fc76c
As well as a decorator :func:`patch` can be used as a context manager in a with statement: >>> with patch.object(ProductionClass, 'method', return_value=None) as mock_method: ... thing = ProductionClass() ... thing.method(1, 2, 3) ... >>> mock_method.assert_called_once_with(1, 2, 3)
trusted_official_docs
CPython Docs
As well as a decorator :func:`patch` can be used as a context manager in a with statement: >>> with patch.object(ProductionClass, 'method', return_value=None) as mock_method: ... thing = ProductionClass() ... thing.method(1, 2, 3) ... >>> mock_method.assert_called_once_with(1, 2, 3)
As well as a decorator :func:`patch` can be used as a context manager in a with statement: >>> with patch.object(ProductionClass, 'method', return_value=None) as mock_method: ... thing = ProductionClass() ... thing.method(1, 2, 3) ... >>> mock_method.assert_called_once_with(1, 2, 3)
python, official-docs, cpython, P0
Local_Trusted_Corpus
3ea2e844-c7ce-41e5-9be6-5e2534a8c030
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,769
supabase-export-v2
e2b12872df94052b
If *clear* is true then the dictionary will be cleared before the new values are set. :func:`patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary.
trusted_official_docs
CPython Docs
If *clear* is true then the dictionary will be cleared before the new values are set. :func:`patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary.
If *clear* is true then the dictionary will be cleared before the new values are set. :func:`patch.dict` can also be called with arbitrary keyword arguments to set values in the dictionary.
python, official-docs, cpython, P0
Local_Trusted_Corpus
3ecc5c87-9db2-413b-8e10-7a8534a77e0c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,849
supabase-export-v2
125191bf258feeca
>>> 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__.assert_called_with(None, None, None) Calls to magic methods do not appear in :attr:`~Mock.method_calls`, but they are recorde...
trusted_official_docs
CPython Docs
>>> 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__.assert_called_with(None, None, None) Calls to magic methods do not appear in :attr:`~Mock.method_calls`, but they are recorde...
>>> 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__.assert_called_with(None, None, None) Calls to magic methods do not appear in :attr:`~Mock.method_calls`, but they are recorde...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4003eb34-c275-46ec-9a65-503b09688b17
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,923
supabase-export-v2
abe9a8d0a9db5d10
>>> m = MagicMock(return_value=None) >>> m(1) >>> m(1, 2) >>> m(object()) >>> m.mock_calls == [call(1), call(1, 2), ANY] True :data:`ANY` is not limited to comparisons with call objects and so can also be used in test assertions::
trusted_official_docs
CPython Docs
>>> m = MagicMock(return_value=None) >>> m(1) >>> m(1, 2) >>> m(object()) >>> m.mock_calls == [call(1), call(1, 2), ANY] True :data:`ANY` is not limited to comparisons with call objects and so can also be used in test assertions::
>>> m = MagicMock(return_value=None) >>> m(1) >>> m(1, 2) >>> m(object()) >>> m.mock_calls == [call(1), call(1, 2), ANY] True :data:`ANY` is not limited to comparisons with call objects and so can also be used in test assertions::
python, official-docs, cpython, P0
Local_Trusted_Corpus
409c732f-7b41-4e74-8e2a-3d20f73cadca
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,455
supabase-export-v2
0e03372723ae7f07
mocking of Python :ref:`magic methods <magic-methods>`. The easiest way of using magic methods is with the :class:`MagicMock` class. It allows you to do things like: >>> mock = MagicMock() >>> mock.__str__.return_value = 'foobarbaz' >>> str(mock) 'foobarbaz' >>> mock.__str__.assert_called_with()
trusted_official_docs
CPython Docs
mocking of Python :ref:`magic methods <magic-methods>`. The easiest way of using magic methods is with the :class:`MagicMock` class. It allows you to do things like: >>> mock = MagicMock() >>> mock.__str__.return_value = 'foobarbaz' >>> str(mock) 'foobarbaz' >>> mock.__str__.assert_called_with()
mocking of Python :ref:`magic methods <magic-methods>`. The easiest way of using magic methods is with the :class:`MagicMock` class. It allows you to do things like: >>> mock = MagicMock() >>> mock.__str__.return_value = 'foobarbaz' >>> str(mock) 'foobarbaz' >>> mock.__str__.assert_called_with()
python, official-docs, cpython, P0
Local_Trusted_Corpus
40d2b1ad-f136-4a3b-b574-970ab89d1b98
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,719
supabase-export-v2
23988c9c947d27a9
must be importable from the environment you are calling :func:`patch` from. The target is imported when the decorated function is executed, not at decoration time. The *spec* and *spec_set* keyword arguments are passed to the :class:`MagicMock` if patch is creating one for you.
trusted_official_docs
CPython Docs
must be importable from the environment you are calling :func:`patch` from. The target is imported when the decorated function is executed, not at decoration time. The *spec* and *spec_set* keyword arguments are passed to the :class:`MagicMock` if patch is creating one for you.
must be importable from the environment you are calling :func:`patch` from. The target is imported when the decorated function is executed, not at decoration time. The *spec* and *spec_set* keyword arguments are passed to the :class:`MagicMock` if patch is creating one for you.
python, official-docs, cpython, P0
Local_Trusted_Corpus
4101185b-1de6-434f-9339-1ce73e2a25de
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,750
supabase-export-v2
fa80b990ef013858
but adding ``create=True`` in the call to :func:`patch` will make the previous example work as expected:: >>> @patch('sys.non_existing_attribute', 42, create=True) ... def test(mock_stdout): ... assert sys.non_existing_attribute == 42 ... >>> test()
trusted_official_docs
CPython Docs
but adding ``create=True`` in the call to :func:`patch` will make the previous example work as expected:: >>> @patch('sys.non_existing_attribute', 42, create=True) ... def test(mock_stdout): ... assert sys.non_existing_attribute == 42 ... >>> test()
but adding ``create=True`` in the call to :func:`patch` will make the previous example work as expected:: >>> @patch('sys.non_existing_attribute', 42, create=True) ... def test(mock_stdout): ... assert sys.non_existing_attribute == 42 ... >>> test()
python, official-docs, cpython, P0
Local_Trusted_Corpus
419c2d86-3f69-4c4c-8ac7-9a0d3cc34c6f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,721
supabase-export-v2
d835ef089d4264be
In addition you can pass ``spec=True`` or ``spec_set=True``, which causes patch to pass in the object being mocked as the spec/spec_set object. *new_callable* allows you to specify a different class, or callable object, that will be called to create the *new* object. By default :class:`AsyncMock` is used for async fu...
trusted_official_docs
CPython Docs
In addition you can pass ``spec=True`` or ``spec_set=True``, which causes patch to pass in the object being mocked as the spec/spec_set object. *new_callable* allows you to specify a different class, or callable object, that will be called to create the *new* object. By default :class:`AsyncMock` is used for async fu...
In addition you can pass ``spec=True`` or ``spec_set=True``, which causes patch to pass in the object being mocked as the spec/spec_set object. *new_callable* allows you to specify a different class, or callable object, that will be called to create the *new* object. By default :class:`AsyncMock` is used for async fu...
python, official-docs, cpython, P0
Local_Trusted_Corpus
425086ad-4d70-43cd-a652-7d1e190bdbcc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,777
supabase-export-v2
0a50b6a344ab0034
test, you can inform the patchers of the different prefix by setting ``patch.TEST_PREFIX``. For more details about how to change the value of see :ref:`test-prefix`. :func:`patch.dict` can be used to add members to a dictionary, or simply let a test change a dictionary, and ensure the dictionary is restored when the te...
trusted_official_docs
CPython Docs
test, you can inform the patchers of the different prefix by setting ``patch.TEST_PREFIX``. For more details about how to change the value of see :ref:`test-prefix`. :func:`patch.dict` can be used to add members to a dictionary, or simply let a test change a dictionary, and ensure the dictionary is restored when the te...
test, you can inform the patchers of the different prefix by setting ``patch.TEST_PREFIX``. For more details about how to change the value of see :ref:`test-prefix`. :func:`patch.dict` can be used to add members to a dictionary, or simply let a test change a dictionary, and ensure the dictionary is restored when the te...
python, official-docs, cpython, P0
Local_Trusted_Corpus
426250f5-7105-4cfb-b4dc-4bc9abcb34f9
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,695
supabase-export-v2
76845954b078b634
Mock objects create attributes on demand. This allows them to pretend to be objects of any type. You may want a mock object to return ``False`` to a :func:`hasattr` call, or raise an :exc:`AttributeError` when an attribute is fetched. You can do this by providing an object as a :attr:`!spec` for a mock, but that isn't ...
trusted_official_docs
CPython Docs
Mock objects create attributes on demand. This allows them to pretend to be objects of any type. You may want a mock object to return ``False`` to a :func:`hasattr` call, or raise an :exc:`AttributeError` when an attribute is fetched. You can do this by providing an object as a :attr:`!spec` for a mock, but that isn't ...
Mock objects create attributes on demand. This allows them to pretend to be objects of any type. You may want a mock object to return ``False`` to a :func:`hasattr` call, or raise an :exc:`AttributeError` when an attribute is fetched. You can do this by providing an object as a :attr:`!spec` for a mock, but that isn't ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4684b861-ca33-4167-8fa4-570f833250f0
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,630
supabase-export-v2
ae4614d616956cf9
that the mock was awaited at least once. Note that this is separate from the object having been called, the ``await`` keyword must be used: >>> mock = AsyncMock() >>> async def main(coroutine_mock): ... await coroutine_mock ... >>> coroutine_mock = mock() >>> mock.called True >>> mock.assert_awaited() Traceback ...
trusted_official_docs
CPython Docs
that the mock was awaited at least once. Note that this is separate from the object having been called, the ``await`` keyword must be used: >>> mock = AsyncMock() >>> async def main(coroutine_mock): ... await coroutine_mock ... >>> coroutine_mock = mock() >>> mock.called True >>> mock.assert_awaited() Traceback ...
that the mock was awaited at least once. Note that this is separate from the object having been called, the ``await`` keyword must be used: >>> mock = AsyncMock() >>> async def main(coroutine_mock): ... await coroutine_mock ... >>> coroutine_mock = mock() >>> mock.called True >>> mock.assert_awaited() Traceback ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
46b00a8e-746e-42de-a0e0-c695eced84ae
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,467
supabase-export-v2
3a6f3ef5cd8b8300
magic methods pre-created and ready to use. There are also non-callable variants, useful when you are mocking out objects that aren't callable: :class:`NonCallableMock` and :class:`NonCallableMagicMock` The :func:`patch` decorators makes it easy to temporarily replace classes in a particular module with a :class:`Mock`...
trusted_official_docs
CPython Docs
magic methods pre-created and ready to use. There are also non-callable variants, useful when you are mocking out objects that aren't callable: :class:`NonCallableMock` and :class:`NonCallableMagicMock` The :func:`patch` decorators makes it easy to temporarily replace classes in a particular module with a :class:`Mock`...
magic methods pre-created and ready to use. There are also non-callable variants, useful when you are mocking out objects that aren't callable: :class:`NonCallableMock` and :class:`NonCallableMagicMock` The :func:`patch` decorators makes it easy to temporarily replace classes in a particular module with a :class:`Mock`...
python, official-docs, cpython, P0
Local_Trusted_Corpus
491eba65-7aa3-47dd-9ff6-f0dee8b388c8
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,767
supabase-export-v2
65eafcac7661a287
*in_dict* can also be a string specifying the name of the dictionary, which will then be fetched by importing it. *values* can be a dictionary of values to set in the dictionary. *values* can also be an iterable of ``(key, value)`` pairs.
trusted_official_docs
CPython Docs
*in_dict* can also be a string specifying the name of the dictionary, which will then be fetched by importing it. *values* can be a dictionary of values to set in the dictionary. *values* can also be an iterable of ``(key, value)`` pairs.
*in_dict* can also be a string specifying the name of the dictionary, which will then be fetched by importing it. *values* can be a dictionary of values to set in the dictionary. *values* can also be an iterable of ``(key, value)`` pairs.
python, official-docs, cpython, P0
Local_Trusted_Corpus
49d36b81-62cf-4e0c-8ab2-2949365dfc7a
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,729
supabase-export-v2
51beaac106dfe286
"as" then the patched object will be bound to the name after the "as"; very useful if :func:`patch` is creating a mock object for you. :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*...
trusted_official_docs
CPython Docs
"as" then the patched object will be bound to the name after the "as"; very useful if :func:`patch` is creating a mock object for you. :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*...
"as" then the patched object will be bound to the name after the "as"; very useful if :func:`patch` is creating a mock object for you. :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*...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4a29687f-da15-44c8-a855-b3bc8de19d4e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,808
supabase-export-v2
ec79d6ef5246f23d
can be fiddlier than you might think, because if an exception is raised in the ``setUp`` then ``tearDown`` is not called. :meth:`unittest.TestCase.addCleanup` makes this easier:: >>> class MyTest(unittest.TestCase): ... def setUp(self): ... patcher = patch('package.module.Class') ... self.MockClass = patcher.start()...
trusted_official_docs
CPython Docs
can be fiddlier than you might think, because if an exception is raised in the ``setUp`` then ``tearDown`` is not called. :meth:`unittest.TestCase.addCleanup` makes this easier:: >>> class MyTest(unittest.TestCase): ... def setUp(self): ... patcher = patch('package.module.Class') ... self.MockClass = patcher.start()...
can be fiddlier than you might think, because if an exception is raised in the ``setUp`` then ``tearDown`` is not called. :meth:`unittest.TestCase.addCleanup` makes this easier:: >>> class MyTest(unittest.TestCase): ... def setUp(self): ... patcher = patch('package.module.Class') ... self.MockClass = patcher.start()...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4b547a4f-1a6f-42ce-9afc-2fb9872d3d1c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
27,011
supabase-export-v2
d6e9961d3deae929
>>> order_mock.get_value.return_value = "second" >>> order_mock.get_value() 'second' But if you assign ``None`` to it, this will not be ignored as it is an explicit assignment. So, the order of precedence will not move to the wrapped object.
trusted_official_docs
CPython Docs
>>> order_mock.get_value.return_value = "second" >>> order_mock.get_value() 'second' But if you assign ``None`` to it, this will not be ignored as it is an explicit assignment. So, the order of precedence will not move to the wrapped object.
>>> order_mock.get_value.return_value = "second" >>> order_mock.get_value() 'second' But if you assign ``None`` to it, this will not be ignored as it is an explicit assignment. So, the order of precedence will not move to the wrapped object.
python, official-docs, cpython, P0
Local_Trusted_Corpus
4b7eedc6-a049-4c5d-8de8-501c3d6b0f05
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,898
supabase-export-v2
f391653cb3cef10e
For a call object that represents multiple calls, :meth:`call_list` returns a list of all the intermediate calls as well as the final call. ``call_list`` is particularly useful for making assertions on "chained calls". A chained call is multiple calls on a single line of code. This results in multiple entries in :attr:...
trusted_official_docs
CPython Docs
For a call object that represents multiple calls, :meth:`call_list` returns a list of all the intermediate calls as well as the final call. ``call_list`` is particularly useful for making assertions on "chained calls". A chained call is multiple calls on a single line of code. This results in multiple entries in :attr:...
For a call object that represents multiple calls, :meth:`call_list` returns a list of all the intermediate calls as well as the final call. ``call_list`` is particularly useful for making assertions on "chained calls". A chained call is multiple calls on a single line of code. This results in multiple entries in :attr:...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4c263005-debb-4f92-8de6-67398ee01946
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,572
supabase-export-v2
fe89a273f1d1e5b9
(or an empty tuple) and the second member, which can also be accessed through the ``kwargs`` property, is any keyword arguments (or an empty dictionary). >>> mock = Mock(return_value=None) >>> print(mock.call_args) None >>> mock() >>> mock.call_args call() >>> mock.call_args == () True >>> mock(3, 4) >>> mock....
trusted_official_docs
CPython Docs
(or an empty tuple) and the second member, which can also be accessed through the ``kwargs`` property, is any keyword arguments (or an empty dictionary). >>> mock = Mock(return_value=None) >>> print(mock.call_args) None >>> mock() >>> mock.call_args call() >>> mock.call_args == () True >>> mock(3, 4) >>> mock....
(or an empty tuple) and the second member, which can also be accessed through the ``kwargs`` property, is any keyword arguments (or an empty dictionary). >>> mock = Mock(return_value=None) >>> print(mock.call_args) None >>> mock() >>> mock.call_args call() >>> mock.call_args == () True >>> mock(3, 4) >>> mock....
python, official-docs, cpython, P0
Local_Trusted_Corpus
4cd14062-25de-47c5-b8d6-eabf304e92e0
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,975
supabase-export-v2
bc645b355d464de8
may not be able to use autospec. On the other hand it is much better to design your objects so that introspection is safe [#]_. A more serious problem is that it is common for instance attributes to be created in the :meth:`~object.__init__` method and not to exist on the class at all. *autospec* can't know about any d...
trusted_official_docs
CPython Docs
may not be able to use autospec. On the other hand it is much better to design your objects so that introspection is safe [#]_. A more serious problem is that it is common for instance attributes to be created in the :meth:`~object.__init__` method and not to exist on the class at all. *autospec* can't know about any d...
may not be able to use autospec. On the other hand it is much better to design your objects so that introspection is safe [#]_. A more serious problem is that it is common for instance attributes to be created in the :meth:`~object.__init__` method and not to exist on the class at all. *autospec* can't know about any d...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4ce15507-e758-4e82-82e5-73acaed8c3b5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,780
supabase-export-v2
add770cc175a864e
>>> import os >>> with patch.dict('os.environ', {'newkey': 'newvalue'}): ... print(os.environ['newkey']) ... newvalue >>> assert 'newkey' not in os.environ Keywords can be used in the :func:`patch.dict` call to set values in the dictionary:
trusted_official_docs
CPython Docs
>>> import os >>> with patch.dict('os.environ', {'newkey': 'newvalue'}): ... print(os.environ['newkey']) ... newvalue >>> assert 'newkey' not in os.environ Keywords can be used in the :func:`patch.dict` call to set values in the dictionary:
>>> import os >>> with patch.dict('os.environ', {'newkey': 'newvalue'}): ... print(os.environ['newkey']) ... newvalue >>> assert 'newkey' not in os.environ Keywords can be used in the :func:`patch.dict` call to set values in the dictionary:
python, official-docs, cpython, P0
Local_Trusted_Corpus
4d5ea669-3a10-4a2c-a770-01a292664dc7
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,743
supabase-export-v2
fc424826ed4eb90d
io import StringIO >>> def foo(): ... print('Something') ... >>> @patch('sys.stdout', new_callable=StringIO) ... def test(mock_stdout): ... foo() ... assert mock_stdout.getvalue() == 'Something\n' ... >>> test() When :func:`patch` is creating a mock for you, it is common that the first thing you need to do is to config...
trusted_official_docs
CPython Docs
io import StringIO >>> def foo(): ... print('Something') ... >>> @patch('sys.stdout', new_callable=StringIO) ... def test(mock_stdout): ... foo() ... assert mock_stdout.getvalue() == 'Something\n' ... >>> test() When :func:`patch` is creating a mock for you, it is common that the first thing you need to do is to config...
io import StringIO >>> def foo(): ... print('Something') ... >>> @patch('sys.stdout', new_callable=StringIO) ... def test(mock_stdout): ... foo() ... assert mock_stdout.getvalue() == 'Something\n' ... >>> test() When :func:`patch` is creating a mock for you, it is common that the first thing you need to do is to config...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4d83d338-8e12-4f97-a333-532e1b654276
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,571
supabase-export-v2
8c6f1c909c0d80fa
.. attribute:: call_args This is either ``None`` (if the mock hasn't been called), or the arguments that the mock was last called with. This will be in the form of a tuple: the first member, which can also be accessed through the ``args`` property, is any positional arguments the mock was called with (or an empty t...
trusted_official_docs
CPython Docs
.. attribute:: call_args This is either ``None`` (if the mock hasn't been called), or the arguments that the mock was last called with. This will be in the form of a tuple: the first member, which can also be accessed through the ``args`` property, is any positional arguments the mock was called with (or an empty t...
.. attribute:: call_args This is either ``None`` (if the mock hasn't been called), or the arguments that the mock was last called with. This will be in the form of a tuple: the first member, which can also be accessed through the ``args`` property, is any positional arguments the mock was called with (or an empty t...
python, official-docs, cpython, P0
Local_Trusted_Corpus
4e20962e-a06a-44f5-9374-46f932270909
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,966
supabase-export-v2
b57875aedd183573
has a spec. :class:`!request.Request` takes two arguments in the constructor (one of which is *self*). Here's what happens if we try to call it incorrectly:: >>> req = request.Request() Traceback (most recent call last): ... TypeError: <lambda>() takes at least 2 arguments (1 given)
trusted_official_docs
CPython Docs
has a spec. :class:`!request.Request` takes two arguments in the constructor (one of which is *self*). Here's what happens if we try to call it incorrectly:: >>> req = request.Request() Traceback (most recent call last): ... TypeError: <lambda>() takes at least 2 arguments (1 given)
has a spec. :class:`!request.Request` takes two arguments in the constructor (one of which is *self*). Here's what happens if we try to call it incorrectly:: >>> req = request.Request() Traceback (most recent call last): ... TypeError: <lambda>() takes at least 2 arguments (1 given)
python, official-docs, cpython, P0
Local_Trusted_Corpus
50158c60-b4a8-45a0-901e-e50e678b9812
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,598
supabase-export-v2
5dbfda0c7968a2e6
Mock objects that use a class or an instance as a :attr:`!spec` or :attr:`!spec_set` are able to pass :func:`isinstance` tests: >>> mock = Mock(spec=SomeClass) >>> isinstance(mock, SomeClass) True >>> mock = Mock(spec_set=SomeClass()) >>> isinstance(mock, SomeClass) True
trusted_official_docs
CPython Docs
Mock objects that use a class or an instance as a :attr:`!spec` or :attr:`!spec_set` are able to pass :func:`isinstance` tests: >>> mock = Mock(spec=SomeClass) >>> isinstance(mock, SomeClass) True >>> mock = Mock(spec_set=SomeClass()) >>> isinstance(mock, SomeClass) True
Mock objects that use a class or an instance as a :attr:`!spec` or :attr:`!spec_set` are able to pass :func:`isinstance` tests: >>> mock = Mock(spec=SomeClass) >>> isinstance(mock, SomeClass) True >>> mock = Mock(spec_set=SomeClass()) >>> isinstance(mock, SomeClass) True
python, official-docs, cpython, P0
Local_Trusted_Corpus
502cd51d-6285-4111-b88d-c2bee81ab220
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,466
supabase-export-v2
a9cf76b1860aa695
will always return the same mock. Mocks record how you use them, allowing you to make assertions about what your code has done to them. :class:`MagicMock` is a subclass of :class:`Mock` with all the magic methods pre-created and ready to use. There are also non-callable variants, useful when you are mocking out objects...
trusted_official_docs
CPython Docs
will always return the same mock. Mocks record how you use them, allowing you to make assertions about what your code has done to them. :class:`MagicMock` is a subclass of :class:`Mock` with all the magic methods pre-created and ready to use. There are also non-callable variants, useful when you are mocking out objects...
will always return the same mock. Mocks record how you use them, allowing you to make assertions about what your code has done to them. :class:`MagicMock` is a subclass of :class:`Mock` with all the magic methods pre-created and ready to use. There are also non-callable variants, useful when you are mocking out objects...
python, official-docs, cpython, P0
Local_Trusted_Corpus
51fd97a0-e542-4787-9232-882410029f19
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,871
supabase-export-v2
fbd8c6c83d2ea6a8
Methods and their defaults: * ``__lt__``: :data:`NotImplemented` * ``__gt__``: :data:`!NotImplemented` * ``__le__``: :data:`!NotImplemented` * ``__ge__``: :data:`!NotImplemented` * ``__int__``: ``1`` * ``__contains__``: ``False`` * ``__len__``: ``0`` * ``__iter__``: ``iter([])`` * ``__exit__``: ``False`` * ``__aexit__`...
trusted_official_docs
CPython Docs
Methods and their defaults: * ``__lt__``: :data:`NotImplemented` * ``__gt__``: :data:`!NotImplemented` * ``__le__``: :data:`!NotImplemented` * ``__ge__``: :data:`!NotImplemented` * ``__int__``: ``1`` * ``__contains__``: ``False`` * ``__len__``: ``0`` * ``__iter__``: ``iter([])`` * ``__exit__``: ``False`` * ``__aexit__`...
Methods and their defaults: * ``__lt__``: :data:`NotImplemented` * ``__gt__``: :data:`!NotImplemented` * ``__le__``: :data:`!NotImplemented` * ``__ge__``: :data:`!NotImplemented` * ``__int__``: ``1`` * ``__contains__``: ``False`` * ``__len__``: ``0`` * ``__iter__``: ``iter([])`` * ``__exit__``: ``False`` * ``__aexit__`...
python, official-docs, cpython, P0
Local_Trusted_Corpus
52b1d6a6-be0a-43d3-a0c5-9a78f3e64730
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,786
supabase-export-v2
33d4004c90017a35
.. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) Perform multiple patches in a single call. It 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::
trusted_official_docs
CPython Docs
.. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) Perform multiple patches in a single call. It 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::
.. function:: patch.multiple(target, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs) Perform multiple patches in a single call. It 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::
python, official-docs, cpython, P0
Local_Trusted_Corpus
53500505-cecd-4cdd-9ece-163e379ced10
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,482
supabase-export-v2
cf0278ed08082b67
If the mock has an explicit *return_value* set then calls are not passed to the wrapped object and the *return_value* is returned instead. * *name*: If the mock has a 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.
trusted_official_docs
CPython Docs
If the mock has an explicit *return_value* set then calls are not passed to the wrapped object and the *return_value* is returned instead. * *name*: If the mock has a 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.
If the mock has an explicit *return_value* set then calls are not passed to the wrapped object and the *return_value* is returned instead. * *name*: If the mock has a 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.
python, official-docs, cpython, P0
Local_Trusted_Corpus
539ea738-cdb6-4d64-a40b-7543c02671bc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,541
supabase-export-v2
c4f31c255440219d
.. method:: _get_child_mock(**kw) Create the child mocks for attributes and return value. By default child mocks will be the same type as the parent. Subclasses of Mock may want to override this to customize the way child mocks are made.
trusted_official_docs
CPython Docs
.. method:: _get_child_mock(**kw) Create the child mocks for attributes and return value. By default child mocks will be the same type as the parent. Subclasses of Mock may want to override this to customize the way child mocks are made.
.. method:: _get_child_mock(**kw) Create the child mocks for attributes and return value. By default child mocks will be the same type as the parent. Subclasses of Mock may want to override this to customize the way child mocks are made.
python, official-docs, cpython, P0
Local_Trusted_Corpus
53ae65ad-36f9-434f-ac12-7a35f88e136c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,522
supabase-export-v2
1c340a81289d3858
>>> mock = Mock(side_effect=ValueError) >>> mock('hello') Traceback (most recent call last): ... ValueError >>> mock.reset_mock(side_effect=True) >>> mock('hello') # doctest: +ELLIPSIS <Mock name='mock()' id='...'> Note that :meth:`reset_mock` *doesn't* clear the :attr:`return_value`, :attr:`side_effect` or any child ...
trusted_official_docs
CPython Docs
>>> mock = Mock(side_effect=ValueError) >>> mock('hello') Traceback (most recent call last): ... ValueError >>> mock.reset_mock(side_effect=True) >>> mock('hello') # doctest: +ELLIPSIS <Mock name='mock()' id='...'> Note that :meth:`reset_mock` *doesn't* clear the :attr:`return_value`, :attr:`side_effect` or any child ...
>>> mock = Mock(side_effect=ValueError) >>> mock('hello') Traceback (most recent call last): ... ValueError >>> mock.reset_mock(side_effect=True) >>> mock('hello') # doctest: +ELLIPSIS <Mock name='mock()' id='...'> Note that :meth:`reset_mock` *doesn't* clear the :attr:`return_value`, :attr:`side_effect` or any child ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5476420e-0e1c-4aeb-b10a-a0d72864b249
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,704
supabase-export-v2
4dbe478c9b660917
Attaching Mocks as Attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When you attach a mock as an attribute of another mock (or as the return value) it becomes a "child" of that mock. Calls to the child are recorded in the :attr:`~Mock.method_calls` and :attr:`~Mock.mock_calls` attributes of the parent. This is useful for confi...
trusted_official_docs
CPython Docs
Attaching Mocks as Attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When you attach a mock as an attribute of another mock (or as the return value) it becomes a "child" of that mock. Calls to the child are recorded in the :attr:`~Mock.method_calls` and :attr:`~Mock.mock_calls` attributes of the parent. This is useful for confi...
Attaching Mocks as Attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ When you attach a mock as an attribute of another mock (or as the return value) it becomes a "child" of that mock. Calls to the child are recorded in the :attr:`~Mock.method_calls` and :attr:`~Mock.mock_calls` attributes of the parent. This is useful for confi...
python, official-docs, cpython, P0
Local_Trusted_Corpus
54d56a13-1875-4a36-a93f-86e0602a6b1d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,450
supabase-export-v2
eec7d6a66957bc6f
you patch objects in the namespace where they are looked up. This is normally straightforward, but for a quick guide read :ref:`where to patch <where-to-patch>`. As well as a decorator :func:`patch` can be used as a context manager in a with statement:
trusted_official_docs
CPython Docs
you patch objects in the namespace where they are looked up. This is normally straightforward, but for a quick guide read :ref:`where to patch <where-to-patch>`. As well as a decorator :func:`patch` can be used as a context manager in a with statement:
you patch objects in the namespace where they are looked up. This is normally straightforward, but for a quick guide read :ref:`where to patch <where-to-patch>`. As well as a decorator :func:`patch` can be used as a context manager in a with statement:
python, official-docs, cpython, P0
Local_Trusted_Corpus
5636ee4b-4d71-40f2-9823-c15e6d0c9c0d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,589
supabase-export-v2
670bbca075223931
way :attr:`mock_calls` are recorded means that where nested calls are made, the parameters of ancestor calls are not recorded and so will always compare equal: >>> mock = MagicMock() >>> mock.top(a=3).bottom() <MagicMock name='mock.top().bottom()' id='...'> >>> mock.mock_calls [call.top(a=3), call.top().bottom()] ...
trusted_official_docs
CPython Docs
way :attr:`mock_calls` are recorded means that where nested calls are made, the parameters of ancestor calls are not recorded and so will always compare equal: >>> mock = MagicMock() >>> mock.top(a=3).bottom() <MagicMock name='mock.top().bottom()' id='...'> >>> mock.mock_calls [call.top(a=3), call.top().bottom()] ...
way :attr:`mock_calls` are recorded means that where nested calls are made, the parameters of ancestor calls are not recorded and so will always compare equal: >>> mock = MagicMock() >>> mock.top(a=3).bottom() <MagicMock name='mock.top().bottom()' id='...'> >>> mock.mock_calls [call.top(a=3), call.top().bottom()] ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
56f93ccb-8a68-4cb1-96d8-a08e4b03fc1e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,577
supabase-export-v2
c4f4a9685ccfdca4
calls have been made it is an empty list. The :data:`call` object can be used for conveniently constructing lists of calls to compare with :attr:`call_args_list`. >>> mock = Mock(return_value=None) >>> mock() >>> mock(3, 4) >>> mock(key='fish', next='w00t!') >>> mock.call_args_list [call(), call(3, 4), call(key='f...
trusted_official_docs
CPython Docs
calls have been made it is an empty list. The :data:`call` object can be used for conveniently constructing lists of calls to compare with :attr:`call_args_list`. >>> mock = Mock(return_value=None) >>> mock() >>> mock(3, 4) >>> mock(key='fish', next='w00t!') >>> mock.call_args_list [call(), call(3, 4), call(key='f...
calls have been made it is an empty list. The :data:`call` object can be used for conveniently constructing lists of calls to compare with :attr:`call_args_list`. >>> mock = Mock(return_value=None) >>> mock() >>> mock(3, 4) >>> mock(key='fish', next='w00t!') >>> mock.call_args_list [call(), call(3, 4), call(key='f...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5866e9e2-2149-45d1-a653-9eb5daf59848
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,955
supabase-export-v2
b61880df2c694156
.. versionchanged:: 3.5 Before 3.5, tests with a typo in the word assert would silently pass when they should raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock.
trusted_official_docs
CPython Docs
.. versionchanged:: 3.5 Before 3.5, tests with a typo in the word assert would silently pass when they should raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock.
.. versionchanged:: 3.5 Before 3.5, tests with a typo in the word assert would silently pass when they should raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock.
python, official-docs, cpython, P0
Local_Trusted_Corpus
59d5350c-1775-49dc-a29d-af700fd6504c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,533
supabase-export-v2
ec208281f7455098
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: >>> mock = Mock() >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs) >>> mock.method() 3 >>> mock.other() Tracebac...
trusted_official_docs
CPython Docs
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: >>> mock = Mock() >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs) >>> mock.method() 3 >>> mock.other() Tracebac...
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: >>> mock = Mock() >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs) >>> mock.method() 3 >>> mock.other() Tracebac...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5a6fd6b9-e66e-44d0-831c-c8c4dfb65a78
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,691
supabase-export-v2
afad68f42f3005a4
If any members of the iterable are exceptions they will be raised instead of returned:: >>> iterable = (33, ValueError, 66) >>> m = MagicMock(side_effect=iterable) >>> m() 33 >>> m() Traceback (most recent call last): ... ValueError >>> m() 66
trusted_official_docs
CPython Docs
If any members of the iterable are exceptions they will be raised instead of returned:: >>> iterable = (33, ValueError, 66) >>> m = MagicMock(side_effect=iterable) >>> m() 33 >>> m() Traceback (most recent call last): ... ValueError >>> m() 66
If any members of the iterable are exceptions they will be raised instead of returned:: >>> iterable = (33, ValueError, 66) >>> m = MagicMock(side_effect=iterable) >>> m() 33 >>> m() Traceback (most recent call last): ... ValueError >>> m() 66
python, official-docs, cpython, P0
Local_Trusted_Corpus
5c0f4dc6-4816-496b-9a15-add0caec6784
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,446
supabase-export-v2
71317fe8788d5a95
module under test. The object you specify will be replaced with a mock (or other object) during the test and restored when the test ends:: >>> from unittest.mock import patch >>> @patch('module.ClassName2') ... @patch('module.ClassName1') ... def test(MockClass1, MockClass2): ... module.ClassName1() ... module.Cla...
trusted_official_docs
CPython Docs
module under test. The object you specify will be replaced with a mock (or other object) during the test and restored when the test ends:: >>> from unittest.mock import patch >>> @patch('module.ClassName2') ... @patch('module.ClassName1') ... def test(MockClass1, MockClass2): ... module.ClassName1() ... module.Cla...
module under test. The object you specify will be replaced with a mock (or other object) during the test and restored when the test ends:: >>> from unittest.mock import patch >>> @patch('module.ClassName2') ... @patch('module.ClassName1') ... def test(MockClass1, MockClass2): ... module.ClassName1() ... module.Cla...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5c3b089e-c605-4944-91f2-aef904c7200e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,432
supabase-export-v2
b67d8c979bcbcf4e
methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way. Additionally, mock provides a :func:`patch` decorator that handles patching module and class level attributes within the scope of a test, along with :const:`sentinel` for c...
trusted_official_docs
CPython Docs
methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way. Additionally, mock provides a :func:`patch` decorator that handles patching module and class level attributes within the scope of a test, along with :const:`sentinel` for c...
methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way. Additionally, mock provides a :func:`patch` decorator that handles patching module and class level attributes within the scope of a test, along with :const:`sentinel` for c...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5cea0e9e-2f1c-4435-989a-b09204423f8f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,622
supabase-export-v2
8df517d33eec0db2
The result of ``mock()`` is an async function which will have the outcome of ``side_effect`` or ``return_value`` after it has been awaited: - if ``side_effect`` is a function, the async function will return the result of that function, - if ``side_effect`` is an exception, the async function will raise the exception...
trusted_official_docs
CPython Docs
The result of ``mock()`` is an async function which will have the outcome of ``side_effect`` or ``return_value`` after it has been awaited: - if ``side_effect`` is a function, the async function will return the result of that function, - if ``side_effect`` is an exception, the async function will raise the exception...
The result of ``mock()`` is an async function which will have the outcome of ``side_effect`` or ``return_value`` after it has been awaited: - if ``side_effect`` is a function, the async function will return the result of that function, - if ``side_effect`` is an exception, the async function will raise the exception...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5d5ed271-7a89-4b86-b4fd-e238fa0796c6
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,809
supabase-export-v2
368c0cd984ee8c85
class MyTest(unittest.TestCase): ... def setUp(self): ... patcher = patch('package.module.Class') ... self.MockClass = patcher.start() ... self.addCleanup(patcher.stop) ... ... def test_something(self): ... assert package.module.Class is self.MockClass ... As an added bonus you no longer need to keep a reference to the...
trusted_official_docs
CPython Docs
class MyTest(unittest.TestCase): ... def setUp(self): ... patcher = patch('package.module.Class') ... self.MockClass = patcher.start() ... self.addCleanup(patcher.stop) ... ... def test_something(self): ... assert package.module.Class is self.MockClass ... As an added bonus you no longer need to keep a reference to the...
class MyTest(unittest.TestCase): ... def setUp(self): ... patcher = patch('package.module.Class') ... self.MockClass = patcher.start() ... self.addCleanup(patcher.stop) ... ... def test_something(self): ... assert package.module.Class is self.MockClass ... As an added bonus you no longer need to keep a reference to the...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5d8fcbe7-7c35-47e8-9d55-2cd3b5c0d668
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,639
supabase-export-v2
8108698a6095689f
Assert that the mock was awaited exactly once and with the specified arguments. >>> mock = AsyncMock() >>> async def main(*args, **kwargs): ... await mock(*args, **kwargs) ... >>> asyncio.run(main('foo', bar='bar')) >>> mock.assert_awaited_once_with('foo', bar='bar') >>> asyncio.run(main('foo', bar='bar')) >>> mo...
trusted_official_docs
CPython Docs
Assert that the mock was awaited exactly once and with the specified arguments. >>> mock = AsyncMock() >>> async def main(*args, **kwargs): ... await mock(*args, **kwargs) ... >>> asyncio.run(main('foo', bar='bar')) >>> mock.assert_awaited_once_with('foo', bar='bar') >>> asyncio.run(main('foo', bar='bar')) >>> mo...
Assert that the mock was awaited exactly once and with the specified arguments. >>> mock = AsyncMock() >>> async def main(*args, **kwargs): ... await mock(*args, **kwargs) ... >>> asyncio.run(main('foo', bar='bar')) >>> mock.assert_awaited_once_with('foo', bar='bar') >>> asyncio.run(main('foo', bar='bar')) >>> mo...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5e2c15e8-2a48-4834-965f-31d871084f75
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,683
supabase-export-v2
bc13581cf53c03e0
is called with the same arguments as the mock. This allows you to vary the return value of the call dynamically, based on the input: >>> 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)]
trusted_official_docs
CPython Docs
is called with the same arguments as the mock. This allows you to vary the return value of the call dynamically, based on the input: >>> 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)]
is called with the same arguments as the mock. This allows you to vary the return value of the call dynamically, based on the input: >>> 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)]
python, official-docs, cpython, P0
Local_Trusted_Corpus
5e5eac60-adc0-484f-90fa-66730de61ef8
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,585
supabase-export-v2
850585b51789d500
:attr:`mock_calls` records *all* calls to the mock object, its methods, magic methods *and* return value mocks. >>> mock = MagicMock() >>> result = mock(1, 2, 3) >>> mock.first(a=3) <MagicMock name='mock.first()' id='...'> >>> mock.second() <MagicMock name='mock.second()' id='...'> >>> int(mock) 1 >>> result(1)...
trusted_official_docs
CPython Docs
:attr:`mock_calls` records *all* calls to the mock object, its methods, magic methods *and* return value mocks. >>> mock = MagicMock() >>> result = mock(1, 2, 3) >>> mock.first(a=3) <MagicMock name='mock.first()' id='...'> >>> mock.second() <MagicMock name='mock.second()' id='...'> >>> int(mock) 1 >>> result(1)...
:attr:`mock_calls` records *all* calls to the mock object, its methods, magic methods *and* return value mocks. >>> mock = MagicMock() >>> result = mock(1, 2, 3) >>> mock.first(a=3) <MagicMock name='mock.first()' id='...'> >>> mock.second() <MagicMock name='mock.second()' id='...'> >>> int(mock) 1 >>> result(1)...
python, official-docs, cpython, P0
Local_Trusted_Corpus
5f3b3a4a-cb6b-401a-9f5a-6a55807ccea7
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,758
supabase-export-v2
936ab0a818f08ec5
When used as a class decorator :func:`patch.object` honours ``patch.TEST_PREFIX`` for choosing which methods to wrap. You can either call :func:`patch.object` with three 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.
trusted_official_docs
CPython Docs
When used as a class decorator :func:`patch.object` honours ``patch.TEST_PREFIX`` for choosing which methods to wrap. You can either call :func:`patch.object` with three 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 used as a class decorator :func:`patch.object` honours ``patch.TEST_PREFIX`` for choosing which methods to wrap. You can either call :func:`patch.object` with three 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.
python, official-docs, cpython, P0
Local_Trusted_Corpus
60426e66-e7ae-434b-b769-280be64766e3
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,920
supabase-export-v2
11beb62fb53d8b25
arguments you can pass in objects that compare equal to *everything*. Calls to :meth:`~Mock.assert_called_with` and :meth:`~Mock.assert_called_once_with` will then succeed no matter what was passed in. >>> mock = Mock(return_value=None) >>> mock('foo', bar=object()) >>> mock.assert_called_once_with('foo', bar=ANY)
trusted_official_docs
CPython Docs
arguments you can pass in objects that compare equal to *everything*. Calls to :meth:`~Mock.assert_called_with` and :meth:`~Mock.assert_called_once_with` will then succeed no matter what was passed in. >>> mock = Mock(return_value=None) >>> mock('foo', bar=object()) >>> mock.assert_called_once_with('foo', bar=ANY)
arguments you can pass in objects that compare equal to *everything*. Calls to :meth:`~Mock.assert_called_with` and :meth:`~Mock.assert_called_once_with` will then succeed no matter what was passed in. >>> mock = Mock(return_value=None) >>> mock('foo', bar=object()) >>> mock.assert_called_once_with('foo', bar=ANY)
python, official-docs, cpython, P0
Local_Trusted_Corpus
6075e55f-e2eb-4def-a267-8087f33a54a5
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,633
supabase-export-v2
0d65b5a6c309f367
Assert that the mock was awaited exactly once. >>> mock = AsyncMock() >>> async def main(): ... await mock() ... >>> asyncio.run(main()) >>> mock.assert_awaited_once() >>> asyncio.run(main()) >>> mock.assert_awaited_once() Traceback (most recent call last): ... AssertionError: Expected mock to have been awaited...
trusted_official_docs
CPython Docs
Assert that the mock was awaited exactly once. >>> mock = AsyncMock() >>> async def main(): ... await mock() ... >>> asyncio.run(main()) >>> mock.assert_awaited_once() >>> asyncio.run(main()) >>> mock.assert_awaited_once() Traceback (most recent call last): ... AssertionError: Expected mock to have been awaited...
Assert that the mock was awaited exactly once. >>> mock = AsyncMock() >>> async def main(): ... await mock() ... >>> asyncio.run(main()) >>> mock.assert_awaited_once() >>> asyncio.run(main()) >>> mock.assert_awaited_once() Traceback (most recent call last): ... AssertionError: Expected mock to have been awaited...
python, official-docs, cpython, P0
Local_Trusted_Corpus
618b3dc4-9d7e-47e9-93ee-9b169e0c3ae8
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,475
supabase-export-v2
3eb47464d4447792
Alternatively *side_effect* can be an exception class or instance. In this case the exception will be raised when the mock is called. If *side_effect* is an iterable then each call to the mock will return the next value from the iterable.
trusted_official_docs
CPython Docs
Alternatively *side_effect* can be an exception class or instance. In this case the exception will be raised when the mock is called. If *side_effect* is an iterable then each call to the mock will return the next value from the iterable.
Alternatively *side_effect* can be an exception class or instance. In this case the exception will be raised when the mock is called. If *side_effect* is an iterable then each call to the mock will return the next value from the iterable.
python, official-docs, cpython, P0
Local_Trusted_Corpus
61930070-d2ee-47e5-91a6-d01e143fc031
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,789
supabase-export-v2
bff054256d26b2d0
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 context manager. :func:`patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments *spec*, *spec_set*, *create*, *autospec* and *new_callab...
trusted_official_docs
CPython Docs
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 context manager. :func:`patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments *spec*, *spec_set*, *create*, *autospec* and *new_callab...
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 context manager. :func:`patch.multiple` can be used as a decorator, class decorator or a context manager. The arguments *spec*, *spec_set*, *create*, *autospec* and *new_callab...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6268dd13-e443-4473-9c75-0f761295a303
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,964
supabase-export-v2
39aea09a94547889
Here's an example of it in use:: >>> from urllib import request >>> patcher = patch('__main__.request', autospec=True) >>> mock_request = patcher.start() >>> request is mock_request True >>> mock_request.Request <MagicMock name='request.Request' spec='Request' id='...'>
trusted_official_docs
CPython Docs
Here's an example of it in use:: >>> from urllib import request >>> patcher = patch('__main__.request', autospec=True) >>> mock_request = patcher.start() >>> request is mock_request True >>> mock_request.Request <MagicMock name='request.Request' spec='Request' id='...'>
Here's an example of it in use:: >>> from urllib import request >>> patcher = patch('__main__.request', autospec=True) >>> mock_request = patcher.start() >>> request is mock_request True >>> mock_request.Request <MagicMock name='request.Request' spec='Request' id='...'>
python, official-docs, cpython, P0
Local_Trusted_Corpus
62a215d7-6338-458f-a394-6718c72697a8
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,610
supabase-export-v2
6f15cebda49364f8
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. Fetching a :class:`PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock...
trusted_official_docs
CPython Docs
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. Fetching a :class:`PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock...
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. Fetching a :class:`PropertyMock` instance from an object calls the mock, with no args. Setting it calls the mock...
python, official-docs, cpython, P0
Local_Trusted_Corpus
62ba3b21-3b9d-4f11-a151-38fc00cd1152
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,970
supabase-export-v2
620778e27262398d
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 the correct error:: >>> req.add_header('spam', 'eggs') <MagicMock name='request.Request().add_header()' id='...'> >>> req.add_header.assret_called_with # Intentional typo! Trace...
trusted_official_docs
CPython Docs
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 the correct error:: >>> req.add_header('spam', 'eggs') <MagicMock name='request.Request().add_header()' id='...'> >>> req.add_header.assret_called_with # Intentional typo! Trace...
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 the correct error:: >>> req.add_header('spam', 'eggs') <MagicMock name='request.Request().add_header()' id='...'> >>> req.add_header.assret_called_with # Intentional typo! Trace...
python, official-docs, cpython, P0
Local_Trusted_Corpus
62d94844-18aa-4005-8f53-709ad5fc395a
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,647
supabase-export-v2
5fc70d5d5b269542
If *any_order* is true then the awaits can be in any order, but they must all appear in :attr:`await_args_list`. >>> mock = AsyncMock() >>> async def main(*args, **kwargs): ... await mock(*args, **kwargs) ... >>> calls = [call("foo"), call("bar")] >>> mock.assert_has_awaits(calls) Traceback (most recent call last)...
trusted_official_docs
CPython Docs
If *any_order* is true then the awaits can be in any order, but they must all appear in :attr:`await_args_list`. >>> mock = AsyncMock() >>> async def main(*args, **kwargs): ... await mock(*args, **kwargs) ... >>> calls = [call("foo"), call("bar")] >>> mock.assert_has_awaits(calls) Traceback (most recent call last)...
If *any_order* is true then the awaits can be in any order, but they must all appear in :attr:`await_args_list`. >>> mock = AsyncMock() >>> async def main(*args, **kwargs): ... await mock(*args, **kwargs) ... >>> calls = [call("foo"), call("bar")] >>> mock.assert_has_awaits(calls) Traceback (most recent call last)...
python, official-docs, cpython, P0
Local_Trusted_Corpus
63841dd7-41af-46b2-b776-fe91bdf03c56
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,727
supabase-export-v2
e6cb0c30a912dff0
.. versionchanged:: 3.5 If you are patching builtins in a module then you don't need to pass ``create=True``, it will be added by default. Patch can be used as a :class:`~unittest.TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods ...
trusted_official_docs
CPython Docs
.. versionchanged:: 3.5 If you are patching builtins in a module then you don't need to pass ``create=True``, it will be added by default. Patch can be used as a :class:`~unittest.TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods ...
.. versionchanged:: 3.5 If you are patching builtins in a module then you don't need to pass ``create=True``, it will be added by default. Patch can be used as a :class:`~unittest.TestCase` class decorator. It works by decorating each test method in the class. This reduces the boilerplate code when your test methods ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6385b4c2-b3f4-4f9c-af59-1950c9b86c52
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,856
supabase-export-v2
25161088e941f2b8
.. versionchanged:: 3.8 Added support for ``__aenter__``, ``__aexit__``, ``__aiter__`` and ``__anext__``. The following methods exist but are *not* supported as they are either in use by mock, can't be set dynamically, or can cause problems:
trusted_official_docs
CPython Docs
.. versionchanged:: 3.8 Added support for ``__aenter__``, ``__aexit__``, ``__aiter__`` and ``__anext__``. The following methods exist but are *not* supported as they are either in use by mock, can't be set dynamically, or can cause problems:
.. versionchanged:: 3.8 Added support for ``__aenter__``, ``__aexit__``, ``__aiter__`` and ``__anext__``. The following methods exist but are *not* supported as they are either in use by mock, can't be set dynamically, or can cause problems:
python, official-docs, cpython, P0
Local_Trusted_Corpus
639cde1f-2b80-464a-80e2-b863d272cd6f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,866
supabase-export-v2
d225bf101fcee93d
A non-callable version of :class:`MagicMock`. The constructor parameters have the same meaning as for :class:`MagicMock`, with the exception of *return_value* and *side_effect* which have no meaning on a non-callable mock.
trusted_official_docs
CPython Docs
A non-callable version of :class:`MagicMock`. The constructor parameters have the same meaning as for :class:`MagicMock`, with the exception of *return_value* and *side_effect* which have no meaning on a non-callable mock.
A non-callable version of :class:`MagicMock`. The constructor parameters have the same meaning as for :class:`MagicMock`, 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
6426059e-3399-4aff-83fa-f59c91bcd7c7
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,707
supabase-export-v2
d8b66823e79bb5f0
this is if the mock has a name. This allows you to prevent the "parenting" if for some reason you don't want it to happen. >>> mock = MagicMock() >>> not_a_child = MagicMock(name='not-a-child') >>> mock.attribute = not_a_child >>> mock.attribute() <MagicMock name='not-a-child()' id='...'> >>> mock.mock_calls []
trusted_official_docs
CPython Docs
this is if the mock has a name. This allows you to prevent the "parenting" if for some reason you don't want it to happen. >>> mock = MagicMock() >>> not_a_child = MagicMock(name='not-a-child') >>> mock.attribute = not_a_child >>> mock.attribute() <MagicMock name='not-a-child()' id='...'> >>> mock.mock_calls []
this is if the mock has a name. This allows you to prevent the "parenting" if for some reason you don't want it to happen. >>> mock = MagicMock() >>> not_a_child = MagicMock(name='not-a-child') >>> mock.attribute = not_a_child >>> mock.attribute() <MagicMock name='not-a-child()' id='...'> >>> mock.mock_calls []
python, official-docs, cpython, P0
Local_Trusted_Corpus
646c98f9-5021-4331-80cd-c25d56383e1d
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,560
supabase-export-v2
756cbbcee1c399ef
exception instance to be raised, or a value to be returned from the call to the mock (:data:`DEFAULT` handling is identical to the function case). An example of a mock that raises an exception (to test exception handling of an API):
trusted_official_docs
CPython Docs
exception instance to be raised, or a value to be returned from the call to the mock (:data:`DEFAULT` handling is identical to the function case). An example of a mock that raises an exception (to test exception handling of an API):
exception instance to be raised, or a value to be returned from the call to the mock (:data:`DEFAULT` handling is identical to the function case). An example of a mock that raises an exception (to test exception handling of an API):
python, official-docs, cpython, P0
Local_Trusted_Corpus
6571e25e-d9ef-487b-8a37-b2bcb13175ba
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,956
supabase-export-v2
405b0ac4eaced5e1
typo in the word assert would silently pass when they should raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock. Note that this is another reason why you need integration tests as well as unit tests. Testing everything in isolation is all fine and dandy, but if you don't test how you...
trusted_official_docs
CPython Docs
typo in the word assert would silently pass when they should raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock. Note that this is another reason why you need integration tests as well as unit tests. Testing everything in isolation is all fine and dandy, but if you don't test how you...
typo in the word assert would silently pass when they should raise an error. You can still achieve this behavior by passing ``unsafe=True`` to Mock. Note that this is another reason why you need integration tests as well as unit tests. Testing everything in isolation is all fine and dandy, but if you don't test how you...
python, official-docs, cpython, P0
Local_Trusted_Corpus
678c18ab-9105-4059-914e-96066d2c165f
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,902
supabase-export-v2
e068a755c637b8e0
.. _calls-as-tuples: A ``call`` object is either a tuple of (positional args, keyword args) or (name, positional args, keyword args) depending on how it was constructed. When you construct them yourself this isn't particularly interesting, but the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock.cal...
trusted_official_docs
CPython Docs
.. _calls-as-tuples: A ``call`` object is either a tuple of (positional args, keyword args) or (name, positional args, keyword args) depending on how it was constructed. When you construct them yourself this isn't particularly interesting, but the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock.cal...
.. _calls-as-tuples: A ``call`` object is either a tuple of (positional args, keyword args) or (name, positional args, keyword args) depending on how it was constructed. When you construct them yourself this isn't particularly interesting, but the ``call`` objects that are in the :attr:`Mock.call_args`, :attr:`Mock.cal...
python, official-docs, cpython, P0
Local_Trusted_Corpus
68ac4318-9296-41e8-9a00-7d91823e3ffc
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,597
supabase-export-v2
d4f62c08e2e494e3
: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. Mock objects that use a class or an instance as a :attr:`!spec` or :attr:`!spec_set` are able to pass :func:`isinstance` tests:
trusted_official_docs
CPython Docs
: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. Mock objects that use a class or an instance as a :attr:`!spec` or :attr:`!spec_set` are able to pass :func:`isinstance` tests:
: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. Mock objects that use a class or an instance as a :attr:`!spec` or :attr:`!spec_set` are able to pass :func:`isinstance` tests:
python, official-docs, cpython, P0
Local_Trusted_Corpus
68d09d80-76d8-4895-b52c-2eee8d151beb
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,899
supabase-export-v2
20ae58303c1d8a36
on a single line of code. This results in multiple entries in :attr:`~Mock.mock_calls` on a mock. Manually constructing the sequence of calls can be tedious. :meth:`~call.call_list` can construct the sequence of calls from the same chained call:
trusted_official_docs
CPython Docs
on a single line of code. This results in multiple entries in :attr:`~Mock.mock_calls` on a mock. Manually constructing the sequence of calls can be tedious. :meth:`~call.call_list` can construct the sequence of calls from the same chained call:
on a single line of code. This results in multiple entries in :attr:`~Mock.mock_calls` on a mock. Manually constructing the sequence of calls can be tedious. :meth:`~call.call_list` can construct the sequence of calls from the same chained call:
python, official-docs, cpython, P0
Local_Trusted_Corpus
6a57cf3b-80b2-4a32-b036-ce557d181537
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,853
supabase-export-v2
64f26efe6a84cac6
The full list of supported magic methods is: * ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__`` * ``__dir__``, ``__format__`` and ``__subclasses__`` * ``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__`` * Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``, ``__eq__`` and ``__ne__`` * Contai...
trusted_official_docs
CPython Docs
The full list of supported magic methods is: * ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__`` * ``__dir__``, ``__format__`` and ``__subclasses__`` * ``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__`` * Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``, ``__eq__`` and ``__ne__`` * Contai...
The full list of supported magic methods is: * ``__hash__``, ``__sizeof__``, ``__repr__`` and ``__str__`` * ``__dir__``, ``__format__`` and ``__subclasses__`` * ``__round__``, ``__floor__``, ``__trunc__`` and ``__ceil__`` * Comparisons: ``__lt__``, ``__gt__``, ``__le__``, ``__ge__``, ``__eq__`` and ``__ne__`` * Contai...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6ad2e099-0bb0-40b9-ac3e-c3da7cbac9b7
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,764
supabase-export-v2
9cd0deb96983deef
.. function:: patch.dict(in_dict, values=(), clear=False, **kwargs) Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test.
trusted_official_docs
CPython Docs
.. function:: patch.dict(in_dict, values=(), clear=False, **kwargs) Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test.
.. function:: patch.dict(in_dict, values=(), clear=False, **kwargs) Patch a dictionary, or dictionary like object, and restore the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test.
python, official-docs, cpython, P0
Local_Trusted_Corpus
6bee549f-03c7-44ea-a94b-c3be3920eb5b
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,534
supabase-export-v2
27e9f75c2fac5a9a
>>> mock = Mock() >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs) >>> mock.method() 3 >>> mock.other() Traceback (most recent call last): ... KeyError The same thing can be achieved in the constructor call to mocks:
trusted_official_docs
CPython Docs
>>> mock = Mock() >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs) >>> mock.method() 3 >>> mock.other() Traceback (most recent call last): ... KeyError The same thing can be achieved in the constructor call to mocks:
>>> mock = Mock() >>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError} >>> mock.configure_mock(**attrs) >>> mock.method() 3 >>> mock.other() Traceback (most recent call last): ... KeyError The same thing can be achieved in the constructor call to mocks:
python, official-docs, cpython, P0
Local_Trusted_Corpus
6c1d03c1-efe3-4835-85d2-107f728832a3
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,736
supabase-export-v2
9c7676c090749daf
To configure return values on methods of *instances* on the patched class you must do this on the :attr:`~Mock.return_value`. For example:: >>> class Class: ... def method(self): ... pass ... >>> with patch('__main__.Class') as MockClass: ... instance = MockClass.return_value ... instance.method.return_value = 'fo...
trusted_official_docs
CPython Docs
To configure return values on methods of *instances* on the patched class you must do this on the :attr:`~Mock.return_value`. For example:: >>> class Class: ... def method(self): ... pass ... >>> with patch('__main__.Class') as MockClass: ... instance = MockClass.return_value ... instance.method.return_value = 'fo...
To configure return values on methods of *instances* on the patched class you must do this on the :attr:`~Mock.return_value`. For example:: >>> class Class: ... def method(self): ... pass ... >>> with patch('__main__.Class') as MockClass: ... instance = MockClass.return_value ... instance.method.return_value = 'fo...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6cf6fee3-efca-4f25-86bb-001a91119045
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,526
supabase-export-v2
2b87390b61290bac
.. method:: mock_add_spec(spec, spec_set=False) Add a spec to a mock. *spec* can either be an object or a list of strings. Only attributes on the *spec* can be fetched as attributes from the mock.
trusted_official_docs
CPython Docs
.. method:: mock_add_spec(spec, spec_set=False) Add a spec to a mock. *spec* can either be an object or a list of strings. Only attributes on the *spec* can be fetched as attributes from the mock.
.. method:: mock_add_spec(spec, spec_set=False) Add a spec to a mock. *spec* can either be an object or a list of strings. Only attributes on the *spec* can be fetched as attributes from the mock.
python, official-docs, cpython, P0
Local_Trusted_Corpus
6d961f9b-99e8-4139-8bce-c5336e2d1769
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,586
supabase-export-v2
47c47930d89015ee
id='...'> >>> int(mock) 1 >>> result(1) <MagicMock name='mock()()' id='...'> >>> expected = [call(1, 2, 3), call.first(a=3), call.second(), ... call.__int__(), call()(1)] >>> mock.mock_calls == expected True Members of :attr:`mock_calls` are :data:`call` objects. These can be unpacked as tuples to get at the individua...
trusted_official_docs
CPython Docs
id='...'> >>> int(mock) 1 >>> result(1) <MagicMock name='mock()()' id='...'> >>> expected = [call(1, 2, 3), call.first(a=3), call.second(), ... call.__int__(), call()(1)] >>> mock.mock_calls == expected True Members of :attr:`mock_calls` are :data:`call` objects. These can be unpacked as tuples to get at the individua...
id='...'> >>> int(mock) 1 >>> result(1) <MagicMock name='mock()()' id='...'> >>> expected = [call(1, 2, 3), call.first(a=3), call.second(), ... call.__int__(), call()(1)] >>> mock.mock_calls == expected True Members of :attr:`mock_calls` are :data:`call` objects. These can be unpacked as tuples to get at the individua...
python, official-docs, cpython, P0
Local_Trusted_Corpus
6e8cfcb1-388e-4ce1-af2e-cdcbaf3ad87e
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,619
supabase-export-v2
282ce4d18d42a1f7
.. class:: AsyncMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs) An asynchronous version of :class:`MagicMock`. The :class:`AsyncMock` object will behave so the object is recognized as an async function, and the result of a call is an awaitable.
trusted_official_docs
CPython Docs
.. class:: AsyncMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs) An asynchronous version of :class:`MagicMock`. The :class:`AsyncMock` object will behave so the object is recognized as an async function, and the result of a call is an awaitable.
.. class:: AsyncMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs) An asynchronous version of :class:`MagicMock`. The :class:`AsyncMock` object will behave so the object is recognized as an async function, and the result of a call is an awaitable.
python, official-docs, cpython, P0
Local_Trusted_Corpus
70851310-382e-4fe8-9c45-78225838ec13
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,460
supabase-export-v2
74fb82c770e0984e
attributes and methods as the objects they are replacing, and any functions and methods (including constructors) have the same call signature as the real object. This ensures that your mocks will fail in the same way as your production code if they are used incorrectly:
trusted_official_docs
CPython Docs
attributes and methods as the objects they are replacing, and any functions and methods (including constructors) have the same call signature as the real object. This ensures that your mocks will fail in the same way as your production code if they are used incorrectly:
attributes and methods as the objects they are replacing, and any functions and methods (including constructors) have the same call signature as the real object. This ensures that your mocks will fail in the same way as your production code if they are used incorrectly:
python, official-docs, cpython, P0
Local_Trusted_Corpus
7107cf4c-2997-4380-9f2b-c8aae92b923c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,834
supabase-export-v2
ab607fbe762dcfec
@patch('b.SomeClass') However, consider the alternative scenario where instead of ``from a import SomeClass`` module b does ``import a`` and ``some_function`` uses ``a.SomeClass``. Both of these import forms are common. In this case the class we want to patch is being looked up in the module and so we have to patch ``a...
trusted_official_docs
CPython Docs
@patch('b.SomeClass') However, consider the alternative scenario where instead of ``from a import SomeClass`` module b does ``import a`` and ``some_function`` uses ``a.SomeClass``. Both of these import forms are common. In this case the class we want to patch is being looked up in the module and so we have to patch ``a...
@patch('b.SomeClass') However, consider the alternative scenario where instead of ``from a import SomeClass`` module b does ``import a`` and ``some_function`` uses ``a.SomeClass``. Both of these import forms are common. In this case the class we want to patch is being looked up in the module and so we have to patch ``a...
python, official-docs, cpython, P0
Local_Trusted_Corpus
71aa012e-c12b-4dd1-9522-15c6bfed3299
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,941
supabase-export-v2
eb9940f8c55243f3
.. versionchanged:: 3.4 Added :meth:`~io.IOBase.readline` and :meth:`~io.IOBase.readlines` support. The mock of :meth:`~io.RawIOBase.read` changed to consume *read_data* rather than returning it on each call. .. versionchanged:: 3.5 *read_data* is now reset on each call to the *mock*.
trusted_official_docs
CPython Docs
.. versionchanged:: 3.4 Added :meth:`~io.IOBase.readline` and :meth:`~io.IOBase.readlines` support. The mock of :meth:`~io.RawIOBase.read` changed to consume *read_data* rather than returning it on each call. .. versionchanged:: 3.5 *read_data* is now reset on each call to the *mock*.
.. versionchanged:: 3.4 Added :meth:`~io.IOBase.readline` and :meth:`~io.IOBase.readlines` support. The mock of :meth:`~io.RawIOBase.read` changed to consume *read_data* rather than returning it on each call. .. versionchanged:: 3.5 *read_data* is now reset on each call to the *mock*.
python, official-docs, cpython, P0
Local_Trusted_Corpus
73cc608a-62f2-4c0e-8d62-00c5e171270a
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,988
supabase-export-v2
a9a475b87c78b6ae
33 ... >>> class SomethingForTest(Something): ... a = 33 ... >>> p = patch('__main__.Something', autospec=SomethingForTest) >>> mock = p.start() >>> mock.a <NonCallableMagicMock name='Something.a' spec='int' id='...'> .. [#] This only applies to classes or already instantiated objects. Calling a mocked class to create...
trusted_official_docs
CPython Docs
33 ... >>> class SomethingForTest(Something): ... a = 33 ... >>> p = patch('__main__.Something', autospec=SomethingForTest) >>> mock = p.start() >>> mock.a <NonCallableMagicMock name='Something.a' spec='int' id='...'> .. [#] This only applies to classes or already instantiated objects. Calling a mocked class to create...
33 ... >>> class SomethingForTest(Something): ... a = 33 ... >>> p = patch('__main__.Something', autospec=SomethingForTest) >>> mock = p.start() >>> mock.a <NonCallableMagicMock name='Something.a' spec='int' id='...'> .. [#] This only applies to classes or already instantiated objects. Calling a mocked class to create...
python, official-docs, cpython, P0
Local_Trusted_Corpus
73f1a371-95b0-4e1d-b034-86590e103c43
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,470
supabase-export-v2
4f22433c8e2bcff8
Create a new :class:`Mock` object. :class:`Mock` takes several optional arguments that specify the behaviour of the Mock object: * *spec*: This can be either a list of strings or an existing object (a class or instance) that acts as the specification for the mock object. If you pass in an object then a list of string...
trusted_official_docs
CPython Docs
Create a new :class:`Mock` object. :class:`Mock` takes several optional arguments that specify the behaviour of the Mock object: * *spec*: This can be either a list of strings or an existing object (a class or instance) that acts as the specification for the mock object. If you pass in an object then a list of string...
Create a new :class:`Mock` object. :class:`Mock` takes several optional arguments that specify the behaviour of the Mock object: * *spec*: This can be either a list of strings or an existing object (a class or instance) that acts as the specification for the mock object. If you pass in an object then a list of string...
python, official-docs, cpython, P0
Local_Trusted_Corpus
742f796b-abbb-4001-b228-932039f60bd3
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,720
supabase-export-v2
0512c645df0d1e6b
The *spec* and *spec_set* keyword arguments are passed to the :class:`MagicMock` if patch is creating one for you. In addition you can pass ``spec=True`` or ``spec_set=True``, which causes patch to pass in the object being mocked as the spec/spec_set object.
trusted_official_docs
CPython Docs
The *spec* and *spec_set* keyword arguments are passed to the :class:`MagicMock` if patch is creating one for you. In addition you can pass ``spec=True`` or ``spec_set=True``, which causes patch to pass in the object being mocked as the spec/spec_set object.
The *spec* and *spec_set* keyword arguments are passed to the :class:`MagicMock` if patch is creating one for you. In addition you can pass ``spec=True`` or ``spec_set=True``, which causes patch to pass in the object being mocked as the spec/spec_set object.
python, official-docs, cpython, P0
Local_Trusted_Corpus
75961466-debc-4791-b1b4-aed5b26a5452
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,765
supabase-export-v2
3051f14fbbd1d66d
the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test. *in_dict* can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys.
trusted_official_docs
CPython Docs
the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test. *in_dict* can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys.
the dictionary to its original state after the test, where the restored dictionary is a copy of the dictionary as it was before the test. *in_dict* can be a dictionary or a mapping like container. If it is a mapping then it must at least support getting, setting and deleting items plus iterating over keys.
python, official-docs, cpython, P0
Local_Trusted_Corpus
75bd3811-1548-4a5e-895f-e116c50b4dc4
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,895
supabase-export-v2
08baea41bf066b76
:func:`call` is a helper object for making simpler assertions, for comparing with :attr:`~Mock.call_args`, :attr:`~Mock.call_args_list`, :attr:`~Mock.mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used with :meth:`~Mock.assert_has_calls`. >>> m = MagicMock(return_value=None) >>> m(1, 2, a='foo', ...
trusted_official_docs
CPython Docs
:func:`call` is a helper object for making simpler assertions, for comparing with :attr:`~Mock.call_args`, :attr:`~Mock.call_args_list`, :attr:`~Mock.mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used with :meth:`~Mock.assert_has_calls`. >>> m = MagicMock(return_value=None) >>> m(1, 2, a='foo', ...
:func:`call` is a helper object for making simpler assertions, for comparing with :attr:`~Mock.call_args`, :attr:`~Mock.call_args_list`, :attr:`~Mock.mock_calls` and :attr:`~Mock.method_calls`. :func:`call` can also be used with :meth:`~Mock.assert_has_calls`. >>> m = MagicMock(return_value=None) >>> m(1, 2, a='foo', ...
python, official-docs, cpython, P0
Local_Trusted_Corpus
761525ce-1dc0-46f1-b0a8-91842efc3c7c
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,591
supabase-export-v2
afc562c141067045
.. attribute:: __class__ Normally the :attr:`!__class__` attribute of an object will return its type. For a mock object with 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:
trusted_official_docs
CPython Docs
.. attribute:: __class__ Normally the :attr:`!__class__` attribute of an object will return its type. For a mock object with 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:
.. attribute:: __class__ Normally the :attr:`!__class__` attribute of an object will return its type. For a mock object with 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:
python, official-docs, cpython, P0
Local_Trusted_Corpus
78096b49-fa89-4a0a-bd84-13cdaaca0f95
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,442
supabase-export-v2
2285faec58efb422
:attr:`~Mock.side_effect` allows you to perform side effects, including raising an exception when a mock is called: >>> from unittest.mock import Mock >>> mock = Mock(side_effect=KeyError('foo')) >>> mock() Traceback (most recent call last): ... KeyError: 'foo'
trusted_official_docs
CPython Docs
:attr:`~Mock.side_effect` allows you to perform side effects, including raising an exception when a mock is called: >>> from unittest.mock import Mock >>> mock = Mock(side_effect=KeyError('foo')) >>> mock() Traceback (most recent call last): ... KeyError: 'foo'
:attr:`~Mock.side_effect` allows you to perform side effects, including raising an exception when a mock is called: >>> from unittest.mock import Mock >>> mock = Mock(side_effect=KeyError('foo')) >>> mock() Traceback (most recent call last): ... KeyError: 'foo'
python, official-docs, cpython, P0
Local_Trusted_Corpus
782efd8b-85f2-46e4-af0a-1cccdb43f0b0
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,501
supabase-export-v2
256fb94cd6b248f8
: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. >>> mock = Mock(return_value=None) >>> mock(1, 2, arg='thing') >>> mock('some', 'thing', 'else') >>> mock.assert_any_call(1, 2, arg='thing')
trusted_official_docs
CPython Docs
: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. >>> mock = Mock(return_value=None) >>> mock(1, 2, arg='thing') >>> mock('some', 'thing', 'else') >>> mock.assert_any_call(1, 2, arg='thing')
: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. >>> mock = Mock(return_value=None) >>> mock(1, 2, arg='thing') >>> mock('some', 'thing', 'else') >>> mock.assert_any_call(1, 2, arg='thing')
python, official-docs, cpython, P0
Local_Trusted_Corpus
78663179-d32d-47d7-bb0d-6783f427b412
CPython Docs
file://datasets/cpython/Doc/library/unittest.mock.rst
unknown
bce24593-a692-4bea-816a-2b489f4af17b
26,914
supabase-export-v2
784348e2be194dc1
:func:`create_autospec` also takes arbitrary keyword arguments that are passed to the constructor of the created mock. See :ref:`auto-speccing` for examples of how to use auto-speccing with :func:`create_autospec` and the *autospec* argument to :func:`patch`.
trusted_official_docs
CPython Docs
:func:`create_autospec` also takes arbitrary keyword arguments that are passed to the constructor of the created mock. See :ref:`auto-speccing` for examples of how to use auto-speccing with :func:`create_autospec` and the *autospec* argument to :func:`patch`.
:func:`create_autospec` also takes arbitrary keyword arguments that are passed to the constructor of the created mock. See :ref:`auto-speccing` for examples of how to use auto-speccing with :func:`create_autospec` and the *autospec* argument to :func:`patch`.
python, official-docs, cpython, P0
Local_Trusted_Corpus