Refactor connecting and clearing databases in testutils.py.