bpo-35330: Don't call the wrapped object if side_effect
is set by mariocj89 · Pull Request #10973 · python/cpython (original) (raw)
When a Mock
instance was used to wrap an object, if side_effect
is used in one of the mocks of it methods, don't call the original implementation and return the result of using the side effect the same way
that it is done with return_value.
This PR also includes a refactor via commit 1a28aab, as after the change the code became even harder to read. The refactor (as it now uses common code), also fixes the test case test_customize_wrapped_object_with_side_effect_iterable_with_default
, as when adding the tests I realized that if a mock has a side effect that is an iterable and one of the values returns DEFAULT
, it will default to return_value
if present but not to the value in wraps
, which is surprising given that if instead of an iterable it is a callable the behaviour is as expected to call wraps
.
Let me know if you want me to take this to a different PR and issue, as it might be worth properly explaining it. I can also get the fix without the refactor, but it'd get quite messy, basically copying the last lines into the iterator part of side_effect
.