cleanup app state before a test too (rewrite of #1732)

cc @dandoveralba @bootstraponline

seems to be working