It looks like a use case for std::sync::Once
:
use std::sync::{Once, ONCE_INIT};
static INIT: Once = ONCE_INIT;
Then in your tests call
INIT.doit(|| unsafe { init(); });
Once
guarantees that your init
will only be executed once, no matter how many times you call INIT.doit()
.