In Rust, is there any way to execute a teardown function after all tests have been run (i.e. at the end of cargo test
) using the standard testing library?
I'm not looking to run a teardown function after each test, as they've been discussed in these related posts:
- How to run setup code before any tests run in Rust?
- How to initialize the logger for integration tests?
These discuss ideas to run:
- setup before each test
- teardown before each test (using
std::panic::catch_unwind
) - setup before all tests (using
std::sync::Once
)
One workaround is a shell script that wraps around the cargo test
call, but I'm still curious if the above is possible.
build.rs
, you must probably configure a profil – Sacha