[FIX] Recover global state after test_util.py (#5824)
authormbaret <55580676+mbaret@users.noreply.github.com>
Fri, 19 Jun 2020 14:35:05 +0000 (15:35 +0100)
committerGitHub <noreply@github.com>
Fri, 19 Jun 2020 14:35:05 +0000 (07:35 -0700)
In test_util.py, a program exit is simulated to test
that the error throwing behaviour is accurate.
Unforunately, this also deletes necessary global state
and so all subsequent tests that run and use tempdir
throw the same error.

This patch is a simple fix to restore the global state
at the end of the test.

Change-Id: I62fef46167e47f6af43271e2ce1db30f54857647

tests/python/contrib/test_util.py

index 55a2b76..816e651 100644 (file)
@@ -39,6 +39,7 @@ def test_tempdir():
   assert os.path.exists(temp_dir.temp_dir)
 
   old_debug_mode = util.TempDirectory._KEEP_FOR_DEBUG
+  old_tempdirs = util.TempDirectory.TEMPDIRS
   try:
     for temp_dir_number in range(0, 3):
       with util.TempDirectory.set_keep_for_debug():
@@ -80,6 +81,7 @@ def test_tempdir():
 
   finally:
     util.TempDirectory.DEBUG_MODE = old_debug_mode
+    util.TempDirectory.TEMPDIRS = old_tempdirs
 
 
 if __name__ == '__main__':