You could use catch_unwind, ideally as part of the actual test harness, or just write a Drop, which get run on unwind (but not if you have panic = "abort" set.
#[cfg(test)]
mod tests {
use anyhow::Error;
#[test]
fn one_plus_one() -> Result<(), Error> {
let sum = 1 + 1;
anyhow::ensure!(sum == 2);
Ok(())
}
}
The error message will contain a backtrace and the sum == 2 expression, which is normally enough to figure out what went wrong. You could always wrap it with your own assert_eq!() or assert_ne!() macro that does anyhow::ensure!($actual == $expected, "{:?} != {:?}", $actual, $expected).