I've seen examples of unittest.mock.patch() and unittest.mock.patch.object() directly using a return_value argument.
Example:
with patch.object(ProductionClass, 'method', return_value=None) as mock_method:
thing = ProductionClass()
thing.method(1, 2, 3)
However, this argument is not officially documented for unittest.mock.patch() nor unittest.mock.patch.object(). (It is however used in the examples of the official documentation).
Is this supported or is it undefined behavior? Is it supposed to be documented and isn't? Do these examples work by coincidence? What does this argument do; does it do something unintuitive, or is it self-explanatory?
From the documentation for mock.patch:
From the documentation of mock.patch.object:
And from the documentation of mock.Mock, where it is actually used:
And for good measure, the documentation of the
return_valueattribute, which shows the usage with examples:Set this to configure the value returned by calling the mock:
The default return value is a mock object and you can configure it in the normal way:
return_valuecan also be set in the constructor:So, as you can see, this is all well documented, though admittedly it may be overlooked at a first glance due to the arguments not present in the signature.