On importance of testing trivial things

George Shuklin
OpsOps
Published in
1 min readFeb 3, 2020

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?

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.