diff options
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index 4edbc8ac..972d8f1b 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -192,12 +192,11 @@ class PyRunner(object): raise CoverageException(msg.format(filename=self.arg0, exc=exc)) # Execute the code object. + # Return to the original directory in case the test code exits in + # a non-existent directory. + cwd = os.getcwd() try: - # Return to the original directory in case the test code exits in - # a non-existent directory. - cwd = os.getcwd() exec(code, main_mod.__dict__) - os.chdir(cwd) except SystemExit: # pylint: disable=try-except-raise # The user called sys.exit(). Just pass it along to the upper # layers, where it will be handled. @@ -236,6 +235,8 @@ class PyRunner(object): raise ExceptionDuringRun(typ, err, tb.tb_next) else: sys.exit(1) + finally: + os.chdir(cwd) def run_python_module(args): |