Closed GoogleCodeExporter closed 9 years ago
I'm afraid I don't understand what you mean by "it can get confusing to define
your arguments in reverse order". Can you provide an example showing how it is
at the moment (hopefully I can then *see* what you mean by confusing) and how
you would like it to be.
Original comment by fuzzyman
on 23 Aug 2010 at 7:58
@patch(os.path.join)
@patch(os.path.isfile)
@patch(os.path.isdir)
def test_method(self, join, isfile, isdir):
#test code here
The above code is wrong, but it's not obvious why (at least to me). The
problem is that the args should have been defined as (self, isdir, isfile,
join) instead, which is reverse order. What's worse is that it's not clear,
but the join parameter will be set to the value of the isdir mock, and the
isdir parameter will be set to the value of the join mock, making it harder to
see where the actual problem is.
Now, mock could reverse the order of the args, and this would make the code
somewhat more intuitive, but that still leaves it open for you to have the
wrong mocks associated with the wrong name. But it could also just provide
them as kwargs, so you could define them in any order, and you will never have
the wrong mock attached to the wrong name.
Hope this makes more sense.
Original comment by danielfalk22@gmail.com
on 31 Aug 2010 at 3:12
Decorators are always applied from inner to outer in Python. Once you know that
the order is natural. I'm afraid I'm not going to do function argument
introspection and use some heuristic to try and 'guess' which mock belongs to
which argument.
Original comment by fuzzyman
on 31 Aug 2010 at 6:24
You wouldn't need introspection if you send the args in as keyword args.
Python would take care of matching the arguments with the proper methods.
But anyway it's not a problem. I know the reason for the reversal and yet
still find it less pleasant to try to reverse it myself, but I've just changed
my copy to work my way. That's the beauty of open source I guess.
Original comment by danielfalk22@gmail.com
on 1 Sep 2010 at 1:26
Ah, I see what you mean. That would require you to use specific names for your
patched functions. It would be backwards compatible and wouldn't work for
patch.object
I think just having a defined order is simpler, it's just a shame the order was
wrong in earlier versions of mock.
Original comment by fuzzyman
on 1 Sep 2010 at 2:10
Original issue reported on code.google.com by
danielfalk22@gmail.com
on 22 Aug 2010 at 10:11