deftest_func(monkeypatch):monkeypatch.setattr('b.subfunc.__defaults__',(1,False))# do testing of func()

This works nicely, there are two downsides though. First of all, it's hacky due
to the use of double underscore methods. But even worse, we have to specify the
default argument for the first kwarg too! That violates the DRY principle and
could be a source of bugs. Sounds familiar, right?

Of course, we could try to retrieve the initial defaults, manipulate them and
then monkey patch the __defaults__ attribute again. But that's even more
hacky...

Using a partial function

A much nicer way is to use partial function application. It's a method mainly
coming from functional programming. You can use it to override the value of some
arguments and/or keyword arguments, yielding a higher order function.

As a short example, let's create a function that adds 2 to an input value: