Moved a load of common setup and teardown code into the new basetest.py.