I also found that I could have another source, say integration_chdir.rs and run: cargo test --tests Unfortunately, I did not find a way to specify --tests as a default option in, for example, Cargo.toml.
--test-threads=1 is an anti-patttern and IMHO should not be used as a solution to any concurrency problems.
The current directory is a global mutable state, and like all global mutable state, it can be guarded with a mutex.
Make a helper function such as with_directory(path, || { closure }) and make it run set_current_dir and the closure under a Mutex, so that only one of them runs at a time.
Use only that function to set the current directory, so that there aren't any "non thread-safe" uses of set_current_dir. Existence of a global mutable current dir is a design flaw in the underlying OS model, so you can't have a 100% guarantee that nothing will change cwd unexpectedly, but you can try.