diff options
Diffstat (limited to 'unittests/utils/nose.py')
-rw-r--r-- | unittests/utils/nose.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/unittests/utils/nose.py b/unittests/utils/nose.py index 42982960a..701b567c9 100644 --- a/unittests/utils/nose.py +++ b/unittests/utils/nose.py @@ -404,3 +404,19 @@ def capture_stderr(func): sys.stderr = restore return _inner + + +@contextmanager +def chdir(goto): + """chdir to a directory and back, guaranteed. + + This contextmanager ensures that after changing directory you cahgne back, + using a try/finally block. + + """ + returnto = getcwd() + os.chdir(goto) + try: + yield + finally: + os.chdir(returnto) |