Provide a helper to copy args
See original GitHub issuemock
will store references in call_args
and call_args_list
(see https://docs.python.org/3/library/unittest.mock-examples.html#coping-with-mutable-arguments).
I think that pytest-mock could provide a helper based on the example from the doc:
from copy import deepcopy
>>> class CopyingMock(MagicMock):
... def __call__(self, *args, **kwargs):
... args = deepcopy(args)
... kwargs = deepcopy(kwargs)
... return super(CopyingMock, self).__call__(*args, **kwargs)
The following works (by extending the pytest-mock mocker
fixture).
@pytest.fixture
def mocker(mocker):
from copy import deepcopy
from mock import MagicMock
class CopyingMock(MagicMock):
def __call__(self, *args, **kwargs):
args = deepcopy(args)
kwargs = deepcopy(kwargs)
return super(CopyingMock, self).__call__(*args, **kwargs)
mocker.CopyingMock = CopyingMock
return mocker
patched = mocker.patch('foo.bar', new_callable=mocker.CopyingMock)
Not sure if that’s helpful enough and/or if there could be a mocker_copy
fixture instead, which would handle new_callable
not only for patch()
.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Developers - Provide a helper to copy args - - Bountysource
Provide a helper to copy args ... mock will store references in call_args and call_args_list (see https://docs.python.org/3/library/unittest.mock-examples.html# ...
Read more >Ember.js: Passing arguments to render helper - Stack Overflow
I looked around on the internet, and it looks like the {{render}} helper used to allow for an optional options hash (which is...
Read more >Function.prototype.bind() - JavaScript - MDN Web Docs - Mozilla
A copy of the given function with the specified this value, and initial arguments (if provided). Description. The bind() function creates a new ......
Read more >Caller argument expression - C# 10.0 draft specifications
Allow developers to capture the expressions passed to a method, to enable better ... but can be made use of through a helper...
Read more >How to use sys.argv in Python with examples - KnowledgeHut
Command Line argument is a way of managing the script or program externally by providing the script name and the input parameters from ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, thanks for the suggestion and patch. 😄
@nicoddemus Nope.
Feel free to take my patch from above.