diff options
author | Dan Hemberger <daniel.hemberger@gmail.com> | 2019-05-30 12:38:09 -0700 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2019-07-06 17:17:42 -0400 |
commit | e5a59865b038ac575c4f8ca9e79c5b4802018ff1 (patch) | |
tree | 2902479cdfe812d6daa61ea2dc713b9ab6acb08a /coverage/execfile.py | |
parent | 0911fe5e8986dc63c3e9fce8815b4730d02f1d01 (diff) | |
download | python-coveragepy-git-e5a59865b038ac575c4f8ca9e79c5b4802018ff1.tar.gz |
Return to the original directory after exec'ing a file
If the file that is exec'd chdirs to a directory that doesn't exist
at the end of the execution, then we will fail to connect to the
SQLite database (due to a failing `os.getcwd` command).
We can easily fix this if we ensure we are in a directory that
exists after executing the foreign code. Returning to the original
directory seems to be a sensible choice.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 4 |
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. |