Added checks before dir deletion in tests