Hence defeating the optimization
So what you're saying is, some custom function that you write yourself is
better than print? I suppose I can't argue with that
Maybe. But then it is hard to tell the difference between "my test
function printed nothing because it is broken, and my test function
printed nothing because it succeeded".
There are good arguments both for and against successful tests printing a
result. Keep in mind that a successful assert doesn't actually print
"nothing" in the interactive interpreter: when it completes, you do get
feedback because Python prints a prompt. Getting feedback that the test
completed successfully is vital. The only question is whether that
feedback should be minimal or verbose.
But in any case, you have misunderstood the assertion. The error message
is printed *if the assert fails*, not if it passes.
Sure -- for unit testing. For interactive exploration, seeing the value of
a variable is better than guessing. That's why a bare object reference in
the interactive interpreter prints itself, but in a script does nothing.