Pierre Ossman added the comment:
I've always been cautious about running patch() manually since it was easy to
miss the cleanup. But those fears might be irrelevant these days when we have
addCleanup().
Still, decorators are a more robust in more complex setups since you don't have
to
Karthikeyan Singaravelan added the comment:
In my test cases I have ended up just ignoring the mock object with a
placeholder if it's not needed. For the given use case you can do this using
patch objects at setUp and tearDown like in
New submission from Pierre Ossman :
Right now if you use unittest.mock.patch() as a decorator it may or may not
pass the object as an argument to the test function. The behaviour is a side
effect of the argument "new" rather than something the caller can explicitly
control.
In many cases