BAckport various refactorings from bug26150.
If a test fails in the setup phase, tear down as much as we had set up.
Stable to default
Merge in default