Add setup and teardown functions

(And make test function add all tests to a queue, to guarantee that
the teardown function always gets called)