Open GoogleCodeExporter opened 8 years ago
The first argument to patch has to be a *string* specifying what you want to be
patched. If you want a mock using the partial as a spec then you can use
mock.create_autospec instead. From the snippet of code you've posted I'm not
sure what your intent is - what did you expect to happen?
Original comment by fuzzyman
on 24 May 2012 at 8:52
I wanted to monkey patch a function (defined by partial application) from
another module using a mock patch and the with syntax. I forgot the syntax of
mock.patch, hence my string mistake. The real snippet of code is that:
with patch("common.pynn_utils.get_rate_encoder") as mock_get_rate_encoder:
mock_get_rate_encoder.return_value = mock_rate_encoder
w = select_kwta_winners(mock_pop, 4)
eq_(w, [(2, 12), (1, 3), (1, 8), (2, 14)])
But I don't need nose for that of course, and my intent may very well make no
sense, so let's forget about it all. For reference, my normal code reads as:
try:
scheduling.nettraining.get_rate_encoder = Mock()
scheduling.nettraining.get_rate_encoder.return_value = mock_rate_encoder
w = select_kwta_winners(mock_pop, 4)
eq_(w, [(2, 12), (1, 3), (1, 8), (2, 14)])
finally:
scheduling.nettraining.get_rate_encoder = common.pynn_utils.get_rate_encoder
Original comment by al.grav...@gmail.com
on 24 May 2012 at 8:45
I'm afraid I still can't work out what you want to happen from those code
snippets. Can you produce a minimal code snippet showing how you would like to
use Mock and why you can't do it already.
Original comment by fuzzyman
on 25 May 2012 at 9:18
Original issue reported on code.google.com by
al.grav...@gmail.com
on 24 May 2012 at 8:49