def test_error_handling():
 class TestException(Exception, ):
  pass
 try:
  with cd('somewhere'):
   raise TestException('Houston, we have a problem.')
 except TestException:
  pass
 finally:
  with cd('else'):
   eq_(env.cwd, 'else')

def test_error_handling ( ) : class TestException ( Exception , ) : pass try : with cd ( 'somewhere' ) : raise TestException ( 'Houston, we have a problem.' ) except TestException : pass finally : with cd ( 'else' ) : eq_ ( env . cwd , 'else' )
cd cleans up after itself even in case of an exception .