Skip to content

Commit

Permalink
Updating tests to confirm sys.path is preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Dec 13, 2019
1 parent 859df86 commit d04eace
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pyutilib/misc/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_run_file3(self):
os.remove(currdir + "import2.log")

def test_run_file_exception(self):
orig_path = list(sys.path)
with self.assertRaisesRegexp(RuntimeError, "raised from __main__"):
pyutilib.misc.run_file(
"import_main_exception.py",
Expand All @@ -65,6 +66,8 @@ def test_run_file_exception(self):
currdir + "import_main_exception.log",
currdir + "import_main_exception.txt")[0])
os.remove(currdir + "import_main_exception.log")
self.assertIsNot(orig_path, sys.path)
self.assertEqual(orig_path, sys.path)


class TestImportFile(unittest.TestCase):
Expand Down Expand Up @@ -95,10 +98,13 @@ def test_import_file_context3(self):
if not "import1" in globals():
self.fail("test_import_file - failed to import the import1.py file")

def test_run_file_exception(self):
def test_import_exception(self):
orig_path = list(sys.path)
with self.assertRaisesRegexp(RuntimeError, "raised during import"):
pyutilib.misc.run_file(
"import_exception.py", execdir=currdir)
self.assertIsNot(orig_path, sys.path)
self.assertEqual(orig_path, sys.path)

def test1(self):
try:
Expand Down

0 comments on commit d04eace

Please sign in to comment.