Search tests: Use on_exit for restoring `persistent_term` state
Otherwise if the assertion failed, the code below which resets the state would never be reached
Otherwise if the assertion failed, the code below which resets the state would never be reached