Restore the ability to run tests from a function.

I overlooked this when reworking the test suite, but @PhML pointed it out on #4320.