In a method that looks like:
def my_method(p):
if p == 5:
return
elif p == 6:
do_something()
return
else:
do_something_different()
return
How do I use Python unit test to check that when I call my_method(5) nothing extra is executed or changed outside my_method? I know that I can mock do_something and do_something_different and use assert_not_called but, is there a way to do it that only considers the if p == 5: part?
do*()all affect some limited portion of the state, you can verify that that portion does not change. But "no side effects at all" is a tall order to prove satisfactorily.coverage. In any case: With code-coverage you'll see what wasn't executed.IOvalue could do anything, including launch nuclear missiles. Here you have a function which is called only for its side effect; there are too many things thatmy_methodcould leave undone to check for all of them.