On importance of testing trivial things
Long ago I have had this rather silly test for my application:
def test_Main_empty_cmdline(commands):
with pytest.raises(SystemExit):
commands.Main([])
It tests if my application exits when there is no arguments in a command line. I wrote it just because of the mantra ‘you shall have 100% code coverage’.
And you won’t believe me, but it actually caught a tricky bug in Py2->Py3 migration. As I found later during bugfixing, argparse has changed behavior:
In py3 you need to add required=True
to subparsers. I absolutely elated that this silly test caught a very annoying and hard to interpret bug in a code caused by subtle changes in underlying libraries.
Isn’t this the true goal of any test?