You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I guess the problem is that during the initial mock creation kwargs is passed so calling test_method immediately after mock creation raises ValueError. But as we loop through the attributes and create new child mock for the attributes the original configured mock for the method that raises ValueError is overridden by another object without the configuration info. Probably it makes sense to call configure_mock again after all children mock are constructed. Something like below works and I don't see any test failures in mock related test cases.
Activity
marchantjm commentedon Feb 9, 2022
When using
create_autospec()to create a mock object, it doesn't respect values passed through in the style described for passing mock configurations in the Mock constructor (https://docs.python.org/3.8/library/unittest.mock.html#unittest.mock.Mock.configure_mock). Instead, they seem to get discarded somewhere here (cpython/Lib/unittest/mock.py
Lines 2693 to 2741 in 77bab59
Here's a simple test case:
tirkarthi commentedon Feb 10, 2022
I guess the problem is that during the initial mock creation kwargs is passed so calling test_method immediately after mock creation raises ValueError. But as we loop through the attributes and create new child mock for the attributes the original configured mock for the method that raises ValueError is overridden by another object without the configuration info. Probably it makes sense to call configure_mock again after all children mock are constructed. Something like below works and I don't see any test failures in mock related test cases.
pythongh-90848: Fixed create_autospec ignoring configure_mock style k…
pythongh-90848: Fixed create_autospec ignoring configure_mock style k…
gh-90848: Fixed create_autospec ignoring configure_mock style kwargs (#…
pythongh-90848: Fixed create_autospec ignoring configure_mock style k…
[3.12] gh-90848: Fixed create_autospec ignoring configure_mock style …
pythongh-90848: Fixed create_autospec ignoring configure_mock style k…