Self-cleaning test

@davert your example seems to overwrite the global after hook. Any idea how to implement the self cleaning test idea without doing so?