-
Notifications
You must be signed in to change notification settings - Fork 23
Description
@t-moe had a great idea for per-test teardown by implementing Drop on the test resource. That should work for happy-path teardown, however it looks like it doesn't work in the case of a panic in a test.
My use case is that I would like to have a test (or suite of tests) that powers on a variety of components (in init) on the board to do checks, however I want to shutdown the power rails gracefully in any result of the tests (pass or fail, including panic) to not drain power or cause the board to get hot or melt lol.
The only way I can seem to get this behavior reliably is having a "final test" that is the last in the file, which isn't actually a test, it just powers off the rails. But according to @bugadani, we shouldn't rely on the tests being run sequentially in-order due to some recent changes. So it seems like a global teardown would be needed here to achieve the use case we are after.
This global teardown I imagine would be the complement to #[init] and would take the resource returned by that function and run the teardown to ensure the board is never left in a bad or unexpected state after failing or panicking a test part-way through.
I think it may be a good idea to run the init before the final teardown as well to ensure it is in a known state going in to the teardown, but that point may be up for debate (may want to keep some state from the previous runs, like some status LED being set for example).