Move os.environ manipulation to pre_cleanup
Simply initializing a loader would empty the environment, which can
cause seemingly unrelated things to break. Moving the environment
handling to the pre_cleanup phase ensures that cleanup will also
be called and the environment will not be left in a broken state.
We also add the HGRCSKIPREPO variable that I forgot to add in the
test environment. This is still needed because the tests invoke
hg directly. We could potentially have a wrapper util that uses a
context-manager to do the environment manipulation closer to the issue,
but we'd have to make sure that no other bare hg invocations can
happen, even in random subprocesses.