Since the test function is interrupted upon failure, you cannot simply clear it at the end of the function being tested.
Use RAII and implement Drop . This eliminates the need to call something:
struct Noisy; impl Drop for Noisy { fn drop(&mut self) { println!("I'm melting! Meeeelllllttttinnnng!"); } } #[test] fn always_fails() { let my_setup = Noisy; assert!(false, "or else...!"); }
running 1 test test always_fails ... FAILED failures: ---- always_fails stdout ---- thread 'always_fails' panicked at 'or else...!', main.rs:12 note: Run with `RUST_BACKTRACE=1` for a backtrace. I'm melting! Meeeelllllttttinnnng! failures: always_fails test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
Shepmaster
source share