#retry #times #attributes #multiple #retrying #macro #test

macro test_retry

Atttribute macro for retrying a test multiple times

1 unstable release

0.1.0 Mar 10, 2023

#4 in #retrying

23 downloads per month

MIT license

4KB

This attribute macro will retry a test multiple times, failing only if all attempts fail. Useful for situations when a test is known to be flaky due to external conditions.

use test_retry::retry;

#[test]
#[retry]
fn my_test() {
  assert_eq!(1, 2);
}

lib.rs:

This crate provides an attribute macro for retrying tests multiple times before failing.

Examples

By default retry will cause the test to be called three times before failing:

use std::sync::atomic::{AtomicUsize, Ordering};

#[test]
#[retry]
fn default() {
  static COUNTER: AtomicUsize = AtomicUsize::new(1);
  assert_eq!(counter.fetch_add(1, Ordering::Relaxed), 3);
}

Dependencies

~1.5MB
~37K SLoC