summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index fbd0228c..4edbc8ac 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -193,7 +193,11 @@ class PyRunner(object):
# 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.