You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unit tests that require creating temporary files on disk need to remove the files explicitly before starting to assert!, so that the files don't remain there if the tests fail.
There's a tempfile crate that can help. According to the documentation:
The temporary file will be automatically removed by the OS when the last handle to it is closed. This doesn't rely on Rust destructors being run, so will (almost) never fail to clean up the temporary file.
This works if the name of the file isn't needed. If it is, cleanup is not guaranteed and our unit tests can remain unchanged (remove before assert!).
The text was updated successfully, but these errors were encountered:
We cannot use tempfile from tempfile crate. We will have to use NamedTempFile because we need the path of the file.
From the crate documentation:
"When choosing between the temporary file variants, prefer tempfile unless you either need to know the file's path or to be able to persist it." https://docs.rs/tempfile/3.0.2/tempfile/index.html
I just wrote another test that needs temporary files, so I can also pick this one up.
Unit tests that require creating temporary files on disk need to remove the files explicitly before starting to
assert!
, so that the files don't remain there if the tests fail.There's a
tempfile
crate that can help. According to the documentation:This works if the name of the file isn't needed. If it is, cleanup is not guaranteed and our unit tests can remain unchanged (
remove
beforeassert!
).The text was updated successfully, but these errors were encountered: