diff --git a/coverage/execfile.py b/coverage/execfile.py index fbd0228c3..4edbc8ac9 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -193,7 +193,11 @@ def run(self): # Execute the code object. 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.