From e5a59865b038ac575c4f8ca9e79c5b4802018ff1 Mon Sep 17 00:00:00 2001 From: Dan Hemberger Date: Thu, 30 May 2019 12:38:09 -0700 Subject: 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. --- coverage/execfile.py | 4 ++++ 1 file changed, 4 insertions(+) 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. -- cgit v1.2.1