test_runner: fix ordering of test hooks
For tests with subtests the before hook was being run after the beforeEach hook, which is the opposite to test suites and expectations.
Also, a function was being used to close over the after hooks, but at the point it was being run the after hooks were not yet set up.
Fixes #47915 (closed)