[TIP] Unit testing functions which call super
dstanek at dstanek.com
Wed Aug 13 16:12:48 PDT 2014
On Wed, Aug 13, 2014 at 6:54 PM, Marcin Tustin <
Marcin.Tustin at dealertrack.com> wrote:
> It’s not question of terminology. What happens if I let the test call
> it’s super is impossible to anticipate (but in practice will be some kind
> of exception). Even if it successfully calls the super methods, the output
> won’t be defined by this code, but some other code, so I can’t usefully
> test anything about it other than its type. If it doesn’t work, then I have
> to deal with those exceptions, but then I can’t very well distinguish
> between exceptions originating in the code I’m testing, and exceptions in
> the super methods. It’s all the usual reasons for mocking out calls.
I think about my tests differently. I don't care how the feature is
implemented all I care about is if it works. Mocking super means that you
can't refactor your code without changing tests.
Do you have any real code to share? I suspect that the method you had in
your original post isn't real production code. But if I just look at that
example the only thing I would mock is `do_some_stuff` because it's a
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python