Improve closeAllFiles and runBeforeFirst
Merge with Master
Fixes after review
Merge pull request #4629 from TomMalbran/tom/tests-utils-updates

Followup updates to #4581 and #4598