code: def test_rgetcwd(monkeypatch, tmpdir):
      from ..misc import rgetcwd
  
      oldpath = tmpdir.strpath
      tmpdir.mkdir("sub").chdir()
      newpath = os.getcwd()
  
      # Path still there
      assert rgetcwd() == newpath
  
      # Remove path
      rmtree(newpath, ignore_errors=True)
      with pytest.raises(OSError):
          os.getcwd()
  
      monkeypatch.setenv("PWD", oldpath)
      assert rgetcwd(error=False) == oldpath
  
      # Test when error should be raised
      with pytest.raises(OSError):
          rgetcwd()
  
      # Deleted env variable
      monkeypatch.delenv("PWD")
      with pytest.raises(OSError):
          rgetcwd(error=False)
  
file_path: nipype/nipype/utils/tests/test_misc.py
imports: import os
  from shutil import rmtree
  import pytest
  from nipype.utils.misc import container_to_string, str2bool, flatten, unflatten, dict_diff
label_desc: Use image node_id 4 for calling a global function with example usage: test_rgetcwd(monkeypatch, tmpdir) without return types