Changed setup of CLI mode in test suite.

If any test fails, the cleanup doesn't get run and the util.readConfig
mock gets left behind. As a result, the rest of the tests in the suite
fail, resulting in lots of false failures. This change tweaks the setup
to detect if the underlying mock is currently in place and cleaning it
up if it is before re-mocking. This should avoid the false negatives.