Shared dropable state between tests

So in my unit tests I need create big file:

#[test]
fn test1() { 
  let temp = create_big_file();
  // test1
  temp.delete();
}

#[test]
fn test2() {
  let temp = create_big_file();
  // test2
  temp.delete();
}

Because of create_big_file is slow, obvious solution to share it between tests.

But how can I do it?

For static variable drop method not called,
and I can not delete big file manually, because of order of execution of tests is not defined.

Usully in test frameworks there is functionality to call something before running any test
and after all tests finished.
Is any such functionality in Rust test framework?

1 Like

You can use a counter to determine whether a test is the last one to exit.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.