doc_content stringlengths 1 386k | doc_id stringlengths 5 188 |
|---|---|
class typing.TypedDict(dict)
Special construct to add type hints to a dictionary. At runtime it is a plain dict. TypedDict declares a dictionary type that expects all of its instances to have a certain set of keys, where each key is associated with a value of a consistent type. This expectation is not checked at runt... | python.library.typing#typing.TypedDict |
class typing.TypeVar
Type variable. Usage: T = TypeVar('T') # Can be anything
A = TypeVar('A', str, bytes) # Must be str or bytes
Type variables exist primarily for the benefit of static type checkers. They serve as the parameters for generic types as well as for generic function definitions. See Generic for more ... | python.library.typing#typing.TypeVar |
typing.TYPE_CHECKING
A special constant that is assumed to be True by 3rd party static type checkers. It is False at runtime. Usage: if TYPE_CHECKING:
import expensive_mod
def fun(arg: 'expensive_mod.SomeType') -> None:
local_var: expensive_mod.AnotherType = other_fun()
The first type annotation must be enc... | python.library.typing#typing.TYPE_CHECKING |
@typing.type_check_only
Decorator to mark a class or function to be unavailable at runtime. This decorator is itself not available at runtime. It is mainly intended to mark classes that are defined in type stub files if an implementation returns an instance of a private class: @type_check_only
class Response: # priv... | python.library.typing#typing.type_check_only |
typing.Union
Union type; Union[X, Y] means either X or Y. To define a union, use e.g. Union[int, str]. Details: The arguments must be types and there must be at least one.
Unions of unions are flattened, e.g.: Union[Union[int, str], float] == Union[int, str, float]
Unions of a single argument vanish, e.g.: Union... | python.library.typing#typing.Union |
class typing.ValuesView(MappingView[VT_co])
A generic version of collections.abc.ValuesView. Deprecated since version 3.9: collections.abc.ValuesView now supports []. See PEP 585 and Generic Alias Type. | python.library.typing#typing.ValuesView |
exception UnboundLocalError
Raised when a reference is made to a local variable in a function or method, but no value has been bound to that variable. This is a subclass of NameError. | python.library.exceptions#UnboundLocalError |
unicodedata — Unicode Database This module provides access to the Unicode Character Database (UCD) which defines character properties for all Unicode characters. The data contained in this database is compiled from the UCD version 13.0.0. The module uses the same names and symbols as defined by Unicode Standard Annex #... | python.library.unicodedata |
unicodedata.bidirectional(chr)
Returns the bidirectional class assigned to the character chr as string. If no such value is defined, an empty string is returned. | python.library.unicodedata#unicodedata.bidirectional |
unicodedata.category(chr)
Returns the general category assigned to the character chr as string. | python.library.unicodedata#unicodedata.category |
unicodedata.combining(chr)
Returns the canonical combining class assigned to the character chr as integer. Returns 0 if no combining class is defined. | python.library.unicodedata#unicodedata.combining |
unicodedata.decimal(chr[, default])
Returns the decimal value assigned to the character chr as integer. If no such value is defined, default is returned, or, if not given, ValueError is raised. | python.library.unicodedata#unicodedata.decimal |
unicodedata.decomposition(chr)
Returns the character decomposition mapping assigned to the character chr as string. An empty string is returned in case no such mapping is defined. | python.library.unicodedata#unicodedata.decomposition |
unicodedata.digit(chr[, default])
Returns the digit value assigned to the character chr as integer. If no such value is defined, default is returned, or, if not given, ValueError is raised. | python.library.unicodedata#unicodedata.digit |
unicodedata.east_asian_width(chr)
Returns the east asian width assigned to the character chr as string. | python.library.unicodedata#unicodedata.east_asian_width |
unicodedata.is_normalized(form, unistr)
Return whether the Unicode string unistr is in the normal form form. Valid values for form are ‘NFC’, ‘NFKC’, ‘NFD’, and ‘NFKD’. New in version 3.8. | python.library.unicodedata#unicodedata.is_normalized |
unicodedata.lookup(name)
Look up character by name. If a character with the given name is found, return the corresponding character. If not found, KeyError is raised. Changed in version 3.3: Support for name aliases 1 and named sequences 2 has been added. | python.library.unicodedata#unicodedata.lookup |
unicodedata.mirrored(chr)
Returns the mirrored property assigned to the character chr as integer. Returns 1 if the character has been identified as a “mirrored” character in bidirectional text, 0 otherwise. | python.library.unicodedata#unicodedata.mirrored |
unicodedata.name(chr[, default])
Returns the name assigned to the character chr as a string. If no name is defined, default is returned, or, if not given, ValueError is raised. | python.library.unicodedata#unicodedata.name |
unicodedata.normalize(form, unistr)
Return the normal form form for the Unicode string unistr. Valid values for form are ‘NFC’, ‘NFKC’, ‘NFD’, and ‘NFKD’. The Unicode standard defines various normalization forms of a Unicode string, based on the definition of canonical equivalence and compatibility equivalence. In Un... | python.library.unicodedata#unicodedata.normalize |
unicodedata.numeric(chr[, default])
Returns the numeric value assigned to the character chr as float. If no such value is defined, default is returned, or, if not given, ValueError is raised. | python.library.unicodedata#unicodedata.numeric |
unicodedata.ucd_3_2_0
This is an object that has the same methods as the entire module, but uses the Unicode database version 3.2 instead, for applications that require this specific version of the Unicode database (such as IDNA). | python.library.unicodedata#unicodedata.ucd_3_2_0 |
unicodedata.unidata_version
The version of the Unicode database used in this module. | python.library.unicodedata#unicodedata.unidata_version |
exception UnicodeDecodeError
Raised when a Unicode-related error occurs during decoding. It is a subclass of UnicodeError. | python.library.exceptions#UnicodeDecodeError |
exception UnicodeEncodeError
Raised when a Unicode-related error occurs during encoding. It is a subclass of UnicodeError. | python.library.exceptions#UnicodeEncodeError |
exception UnicodeError
Raised when a Unicode-related encoding or decoding error occurs. It is a subclass of ValueError. UnicodeError has attributes that describe the encoding or decoding error. For example, err.object[err.start:err.end] gives the particular invalid input that the codec failed on.
encoding
The nam... | python.library.exceptions#UnicodeError |
encoding
The name of the encoding that raised the error. | python.library.exceptions#UnicodeError.encoding |
end
The index after the last invalid data in object. | python.library.exceptions#UnicodeError.end |
object
The object the codec was attempting to encode or decode. | python.library.exceptions#UnicodeError.object |
reason
A string describing the specific codec error. | python.library.exceptions#UnicodeError.reason |
start
The first index of invalid data in object. | python.library.exceptions#UnicodeError.start |
exception UnicodeTranslateError
Raised when a Unicode-related error occurs during translating. It is a subclass of UnicodeError. | python.library.exceptions#UnicodeTranslateError |
exception UnicodeWarning
Base class for warnings related to Unicode. | python.library.exceptions#UnicodeWarning |
unittest — Unit testing framework Source code: Lib/unittest/__init__.py (If you are already familiar with the basic concepts of testing, you might want to skip to the list of assert methods.) The unittest unit testing framework was originally inspired by JUnit and has a similar flavor as major unit testing frameworks i... | python.library.unittest |
unittest.addModuleCleanup(function, /, *args, **kwargs)
Add a function to be called after tearDownModule() to cleanup resources used during the test class. Functions will be called in reverse order to the order they are added (LIFO). They are called with any arguments and keyword arguments passed into addModuleCleanu... | python.library.unittest#unittest.addModuleCleanup |
unittest.defaultTestLoader
Instance of the TestLoader class intended to be shared. If no customization of the TestLoader is needed, this instance can be used instead of repeatedly creating new instances. | python.library.unittest#unittest.defaultTestLoader |
unittest.doModuleCleanups()
This function is called unconditionally after tearDownModule(), or after setUpModule() if setUpModule() raises an exception. It is responsible for calling all the cleanup functions added by addCleanupModule(). If you need cleanup functions to be called prior to tearDownModule() then you ca... | python.library.unittest#unittest.doModuleCleanups |
@unittest.expectedFailure
Mark the test as an expected failure or error. If the test fails or errors it will be considered a success. If the test passes, it will be considered a failure. | python.library.unittest#unittest.expectedFailure |
class unittest.FunctionTestCase(testFunc, setUp=None, tearDown=None, description=None)
This class implements the portion of the TestCase interface which allows the test runner to drive the test, but does not provide the methods which test code can use to check and report errors. This is used to create test cases usin... | python.library.unittest#unittest.FunctionTestCase |
unittest.installHandler()
Install the control-c handler. When a signal.SIGINT is received (usually in response to the user pressing control-c) all registered results have stop() called. | python.library.unittest#unittest.installHandler |
class unittest.IsolatedAsyncioTestCase(methodName='runTest')
This class provides an API similar to TestCase and also accepts coroutines as test functions. New in version 3.8.
coroutine asyncSetUp()
Method called to prepare the test fixture. This is called after setUp(). This is called immediately before calling... | python.library.unittest#unittest.IsolatedAsyncioTestCase |
addAsyncCleanup(function, /, *args, **kwargs)
This method accepts a coroutine that can be used as a cleanup function. | python.library.unittest#unittest.IsolatedAsyncioTestCase.addAsyncCleanup |
coroutine asyncSetUp()
Method called to prepare the test fixture. This is called after setUp(). This is called immediately before calling the test method; other than AssertionError or SkipTest, any exception raised by this method will be considered an error rather than a test failure. The default implementation does ... | python.library.unittest#unittest.IsolatedAsyncioTestCase.asyncSetUp |
coroutine asyncTearDown()
Method called immediately after the test method has been called and the result recorded. This is called before tearDown(). This is called even if the test method raised an exception, so the implementation in subclasses may need to be particularly careful about checking internal state. Any ex... | python.library.unittest#unittest.IsolatedAsyncioTestCase.asyncTearDown |
run(result=None)
Sets up a new event loop to run the test, collecting the result into the TestResult object passed as result. If result is omitted or None, a temporary result object is created (by calling the defaultTestResult() method) and used. The result object is returned to run()’s caller. At the end of the test... | python.library.unittest#unittest.IsolatedAsyncioTestCase.run |
unittest.main(module='__main__', defaultTest=None, argv=None, testRunner=None, testLoader=unittest.defaultTestLoader, exit=True, verbosity=1, failfast=None, catchbreak=None, buffer=None, warnings=None)
A command-line program that loads a set of tests from module and runs them; this is primarily for making test module... | python.library.unittest#unittest.main |
unittest.mock — mock object library New in version 3.3. Source code: Lib/unittest/mock.py unittest.mock is a library for testing in Python. It allows you to replace parts of your system under test with mock objects and make assertions about how they have been used. unittest.mock provides a core Mock class removing th... | python.library.unittest.mock |
unittest.mock.ANY | python.library.unittest.mock#unittest.mock.ANY |
class unittest.mock.AsyncMock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs)
An asynchronous version of MagicMock. The AsyncMock object will behave so the object is recognized as an async function, and the result of a call is an awaitable. >>> mock = A... | python.library.unittest.mock#unittest.mock.AsyncMock |
assert_any_await(*args, **kwargs)
Assert the mock has ever been awaited with the specified arguments. >>> mock = AsyncMock()
>>> async def main(*args, **kwargs):
... await mock(*args, **kwargs)
...
>>> asyncio.run(main('foo', bar='bar'))
>>> asyncio.run(main('hello'))
>>> mock.assert_any_await('foo', bar='bar')
>... | python.library.unittest.mock#unittest.mock.AsyncMock.assert_any_await |
assert_awaited()
Assert 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_a... | python.library.unittest.mock#unittest.mock.AsyncMock.assert_awaited |
assert_awaited_once()
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.method.assert_awaited_once()
Traceback (most recent call last):
...
AssertionError: Expecte... | python.library.unittest.mock#unittest.mock.AsyncMock.assert_awaited_once |
assert_awaited_once_with(*args, **kwargs)
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')
>>> ... | python.library.unittest.mock#unittest.mock.AsyncMock.assert_awaited_once_with |
assert_awaited_with(*args, **kwargs)
Assert that the last await was with the specified arguments. >>> mock = AsyncMock()
>>> async def main(*args, **kwargs):
... await mock(*args, **kwargs)
...
>>> asyncio.run(main('foo', bar='bar'))
>>> mock.assert_awaited_with('foo', bar='bar')
>>> mock.assert_awaited_with('oth... | python.library.unittest.mock#unittest.mock.AsyncMock.assert_awaited_with |
assert_has_awaits(calls, any_order=False)
Assert the mock has been awaited with the specified calls. The await_args_list list is checked for the awaits. If any_order is false then the awaits must be sequential. There can be extra calls before or after the specified awaits. If any_order is true then the awaits can be ... | python.library.unittest.mock#unittest.mock.AsyncMock.assert_has_awaits |
assert_not_awaited()
Assert that the mock was never awaited. >>> mock = AsyncMock()
>>> mock.assert_not_awaited() | python.library.unittest.mock#unittest.mock.AsyncMock.assert_not_awaited |
await_args
This is either None (if the mock hasn’t been awaited), or the arguments that the mock was last awaited with. Functions the same as Mock.call_args. >>> mock = AsyncMock()
>>> async def main(*args):
... await mock(*args)
...
>>> mock.await_args
>>> asyncio.run(main('foo'))
>>> mock.await_args
call('foo')... | python.library.unittest.mock#unittest.mock.AsyncMock.await_args |
await_args_list
This is a list of all the awaits made to the mock object in sequence (so the length of the list is the number of times it has been awaited). Before any awaits have been made it is an empty list. >>> mock = AsyncMock()
>>> async def main(*args):
... await mock(*args)
...
>>> mock.await_args_list
[]... | python.library.unittest.mock#unittest.mock.AsyncMock.await_args_list |
await_count
An integer keeping track of how many times the mock object has been awaited. >>> mock = AsyncMock()
>>> async def main():
... await mock()
...
>>> asyncio.run(main())
>>> mock.await_count
1
>>> asyncio.run(main())
>>> mock.await_count
2 | python.library.unittest.mock#unittest.mock.AsyncMock.await_count |
reset_mock(*args, **kwargs)
See Mock.reset_mock(). Also sets await_count to 0, await_args to None, and clears the await_args_list. | python.library.unittest.mock#unittest.mock.AsyncMock.reset_mock |
unittest.mock.call(*args, **kwargs)
call() is a helper object for making simpler assertions, for comparing with call_args, call_args_list, mock_calls and method_calls. call() can also be used with assert_has_calls(). >>> m = MagicMock(return_value=None)
>>> m(1, 2, a='foo', b='bar')
>>> m()
>>> m.call_args_list == [c... | python.library.unittest.mock#unittest.mock.call |
call.call_list()
For a call object that represents multiple calls, call_list() returns a list of all the intermediate calls as well as the final call. | python.library.unittest.mock#unittest.mock.call.call_list |
unittest.mock.create_autospec(spec, spec_set=False, instance=False, **kwargs)
Create a mock object using another object as a spec. Attributes on the mock will use the corresponding attribute on the spec object as their spec. Functions or methods being mocked will have their arguments checked to ensure that they are c... | python.library.unittest.mock#unittest.mock.create_autospec |
unittest.mock.DEFAULT
The DEFAULT object is a pre-created sentinel (actually sentinel.DEFAULT). It can be used by side_effect functions to indicate that the normal return value should be used. | python.library.unittest.mock#unittest.mock.DEFAULT |
unittest.mock.FILTER_DIR | python.library.unittest.mock#unittest.mock.FILTER_DIR |
class unittest.mock.MagicMock(*args, **kw)
MagicMock is a subclass of Mock with default implementations of most of the magic methods. You can use MagicMock without having to configure the magic methods yourself. The constructor parameters have the same meaning as for Mock. If you use the spec or spec_set arguments th... | python.library.unittest.mock#unittest.mock.MagicMock |
class unittest.mock.Mock(spec=None, side_effect=None, return_value=DEFAULT, wraps=None, name=None, spec_set=None, unsafe=False, **kwargs)
Create a new Mock object. 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... | python.library.unittest.mock#unittest.mock.Mock |
assert_any_call(*args, **kwargs)
assert the mock has been called with the specified arguments. The assert passes if the mock has ever been called, unlike assert_called_with() and assert_called_once_with() that only pass if the call is the most recent one, and in the case of assert_called_once_with() it must also be t... | python.library.unittest.mock#unittest.mock.Mock.assert_any_call |
assert_called()
Assert that the mock was called at least once. >>> mock = Mock()
>>> mock.method()
<Mock name='mock.method()' id='...'>
>>> mock.method.assert_called()
New in version 3.6. | python.library.unittest.mock#unittest.mock.Mock.assert_called |
assert_called_once()
Assert that the mock was called exactly once. >>> mock = Mock()
>>> mock.method()
<Mock name='mock.method()' id='...'>
>>> mock.method.assert_called_once()
>>> mock.method()
<Mock name='mock.method()' id='...'>
>>> mock.method.assert_called_once()
Traceback (most recent call last):
...
AssertionE... | python.library.unittest.mock#unittest.mock.Mock.assert_called_once |
assert_called_once_with(*args, **kwargs)
Assert that the mock was called exactly once and that that call was with the specified arguments. >>> mock = Mock(return_value=None)
>>> mock('foo', bar='baz')
>>> mock.assert_called_once_with('foo', bar='baz')
>>> mock('other', bar='values')
>>> mock.assert_called_once_with('... | python.library.unittest.mock#unittest.mock.Mock.assert_called_once_with |
assert_called_with(*args, **kwargs)
This method is a convenient way of asserting that the last call has been made in a particular way: >>> mock = Mock()
>>> mock.method(1, 2, 3, test='wow')
<Mock name='mock.method()' id='...'>
>>> mock.method.assert_called_with(1, 2, 3, test='wow') | python.library.unittest.mock#unittest.mock.Mock.assert_called_with |
assert_has_calls(calls, any_order=False)
assert the mock has been called with the specified calls. The mock_calls list is checked for the calls. If any_order is false then the calls must be sequential. There can be extra calls before or after the specified calls. If any_order is true then the calls can be in any orde... | python.library.unittest.mock#unittest.mock.Mock.assert_has_calls |
assert_not_called()
Assert the mock was never called. >>> m = Mock()
>>> m.hello.assert_not_called()
>>> obj = m.hello()
>>> m.hello.assert_not_called()
Traceback (most recent call last):
...
AssertionError: Expected 'hello' to not have been called. Called 1 times.
New in version 3.5. | python.library.unittest.mock#unittest.mock.Mock.assert_not_called |
attach_mock(mock, attribute)
Attach a mock as an attribute of this one, replacing its name and parent. Calls to the attached mock will be recorded in the method_calls and mock_calls attributes of this one. | python.library.unittest.mock#unittest.mock.Mock.attach_mock |
called
A boolean representing whether or not the mock object has been called: >>> mock = Mock(return_value=None)
>>> mock.called
False
>>> mock()
>>> mock.called
True | python.library.unittest.mock#unittest.mock.Mock.called |
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 ordered arguments the mock was called with (or an empty tuple) and the second member,... | python.library.unittest.mock#unittest.mock.Mock.call_args |
call_args_list
This is a list of all the calls made to the mock object in sequence (so the length of the list is the number of times it has been called). Before any calls have been made it is an empty list. The call object can be used for conveniently constructing lists of calls to compare with call_args_list. >>> mo... | python.library.unittest.mock#unittest.mock.Mock.call_args_list |
call_count
An integer telling you how many times the mock object has been called: >>> mock = Mock(return_value=None)
>>> mock.call_count
0
>>> mock()
>>> mock()
>>> mock.call_count
2 | python.library.unittest.mock#unittest.mock.Mock.call_count |
configure_mock(**kwargs)
Set attributes on the mock through keyword arguments. Attributes plus return values and side effects can be set on child mocks using standard dot notation and unpacking a dictionary in the method call: >>> mock = Mock()
>>> attrs = {'method.return_value': 3, 'other.side_effect': KeyError}
>>>... | python.library.unittest.mock#unittest.mock.Mock.configure_mock |
method_calls
As well as tracking calls to themselves, mocks also track calls to methods and attributes, and their methods and attributes: >>> mock = Mock()
>>> mock.method()
<Mock name='mock.method()' id='...'>
>>> mock.property.method.attribute()
<Mock name='mock.property.method.attribute()' id='...'>
>>> mock.metho... | python.library.unittest.mock#unittest.mock.Mock.method_calls |
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. If spec_set is true then only attributes on the spec can be set. | python.library.unittest.mock#unittest.mock.Mock.mock_add_spec |
mock_calls
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)
<Magic... | python.library.unittest.mock#unittest.mock.Mock.mock_calls |
reset_mock(*, return_value=False, side_effect=False)
The reset_mock method resets all the call attributes on a mock object: >>> mock = Mock(return_value=None)
>>> mock('hello')
>>> mock.called
True
>>> mock.reset_mock()
>>> mock.called
False
Changed in version 3.6: Added two keyword only argument to the reset_mock ... | python.library.unittest.mock#unittest.mock.Mock.reset_mock |
return_value
Set this to configure the value returned by calling the mock: >>> mock = Mock()
>>> mock.return_value = 'fish'
>>> mock()
'fish'
The default return value is a mock object and you can configure it in the normal way: >>> mock = Mock()
>>> mock.return_value.attribute = sentinel.Attribute
>>> mock.return_va... | python.library.unittest.mock#unittest.mock.Mock.return_value |
side_effect
This can either be a function to be called when the mock is called, an iterable or an exception (class or instance) to be raised. If you pass in a function it will be called with same arguments as the mock and unless the function returns the DEFAULT singleton the call to the mock will then return whatever... | python.library.unittest.mock#unittest.mock.Mock.side_effect |
_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. For non-callable mocks the callable variant will be used (rather than any custom subclass). | python.library.unittest.mock#unittest.mock.Mock._get_child_mock |
__class__
Normally the __class__ attribute of an object will return its type. For a mock object with a spec, __class__ returns the spec class instead. This allows mock objects to pass isinstance() tests for the object they are replacing / masquerading as: >>> mock = Mock(spec=3)
>>> isinstance(mock, int)
True
__clas... | python.library.unittest.mock#unittest.mock.Mock.__class__ |
__dir__()
Mock objects limit the results of dir(some_mock) to useful results. For mocks with a spec this includes all the permitted attributes for the mock. See FILTER_DIR for what this filtering does, and how to switch it off. | python.library.unittest.mock#unittest.mock.Mock.__dir__ |
unittest.mock.mock_open(mock=None, read_data=None)
A helper function to create a mock to replace the use of open(). It works for open() called directly or used as a context manager. The mock argument is the mock object to configure. If None (the default) then a MagicMock will be created for you, with the API limited ... | python.library.unittest.mock#unittest.mock.mock_open |
class unittest.mock.NonCallableMagicMock(*args, **kw)
A non-callable version of MagicMock. The constructor parameters have the same meaning as for MagicMock, with the exception of return_value and side_effect which have no meaning on a non-callable mock. | python.library.unittest.mock#unittest.mock.NonCallableMagicMock |
class unittest.mock.NonCallableMock(spec=None, wraps=None, name=None, spec_set=None, **kwargs)
A non-callable version of Mock. The constructor parameters have the same meaning of Mock, with the exception of return_value and side_effect which have no meaning on a non-callable mock. | python.library.unittest.mock#unittest.mock.NonCallableMock |
unittest.mock.patch(target, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
patch() acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the target is patched with a new object. When the function/with st... | python.library.unittest.mock#unittest.mock.patch |
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. 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 itera... | python.library.unittest.mock#unittest.mock.patch.dict |
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: with patch.multiple(settings... | python.library.unittest.mock#unittest.mock.patch.multiple |
patch.object(target, attribute, new=DEFAULT, spec=None, create=False, spec_set=None, autospec=None, new_callable=None, **kwargs)
patch the named member (attribute) on an object (target) with a mock object. patch.object() can be used as a decorator, class decorator or a context manager. Arguments new, spec, create, sp... | python.library.unittest.mock#unittest.mock.patch.object |
patch.stopall()
Stop all active patches. Only stops patches started with start. | python.library.unittest.mock#unittest.mock.patch.stopall |
class unittest.mock.PropertyMock(*args, **kwargs)
A mock intended to be used as a property, or other descriptor, on a class. PropertyMock provides __get__() and __set__() methods so you can specify a return value when it is fetched. Fetching a PropertyMock instance from an object calls the mock, with no args. Setting... | python.library.unittest.mock#unittest.mock.PropertyMock |
unittest.mock.seal(mock)
Seal will disable the automatic creation of mocks when accessing an attribute of the mock being sealed or any of its attributes that are already mocks recursively. If a mock instance with a name or a spec is assigned to an attribute it won’t be considered in the sealing chain. This allows one... | python.library.unittest.mock#unittest.mock.seal |
unittest.mock.sentinel
The sentinel object provides a convenient way of providing unique objects for your tests. Attributes are created on demand when you access them by name. Accessing the same attribute will always return the same object. The objects returned have a sensible repr so that test failure messages are r... | python.library.unittest.mock#unittest.mock.sentinel |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.