From 3e1c5ccf63732747939d3b6ea390840dbe2696a0 Mon Sep 17 00:00:00 2001 From: wendycwong Date: Wed, 16 Aug 2023 09:07:10 -0700 Subject: [PATCH] GH-15672: Tomas Fryda suggested instead of changing every test, the change should be made in standalone test. He provides the code and I just copied and pasted. (#15675) --- h2o-py/tests/pyunit_utils/utilsPY.py | 12 +++++++++++- ...nit_PUBDEV_8136_check_gamX_saved_serialization.py | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/h2o-py/tests/pyunit_utils/utilsPY.py b/h2o-py/tests/pyunit_utils/utilsPY.py index 7f5bc428127b..eb0f1d6aab19 100644 --- a/h2o-py/tests/pyunit_utils/utilsPY.py +++ b/h2o-py/tests/pyunit_utils/utilsPY.py @@ -687,7 +687,17 @@ def standalone_test(test, init_options={}): h2o.log_and_echo("STARTING TEST "+test.__name__) h2o.log_and_echo("") h2o.log_and_echo("------------------------------------------------------------") - test() + import os + import tempfile + with tempfile.TemporaryDirectory() as dir: # Create a temporary dir that will clean itself + tempfile._once_lock.acquire() # Better lock to avoid race conditions (but since we don't test in multiple threads (to avoid side-effects on the backend) it should not matter) + old_tempdir = tempfile.tempdir + try: + tempfile.tempdir = dir # Tell tempfile to use this temporary dir as the root for all other temporary dirs + test() + finally: + tempfile.tempdir = old_tempdir + tempfile._once_lock.release() def run_tests(tests, run_in_isolation=True, init_options={}): #flatten in case of nested tests/test suites diff --git a/h2o-py/tests/testdir_algos/gam/pyunit_PUBDEV_8136_check_gamX_saved_serialization.py b/h2o-py/tests/testdir_algos/gam/pyunit_PUBDEV_8136_check_gamX_saved_serialization.py index 682022bdf9be..b7ce6eb7f048 100644 --- a/h2o-py/tests/testdir_algos/gam/pyunit_PUBDEV_8136_check_gamX_saved_serialization.py +++ b/h2o-py/tests/testdir_algos/gam/pyunit_PUBDEV_8136_check_gamX_saved_serialization.py @@ -7,7 +7,6 @@ import tempfile import os - # Check and make sure transformed gam frame is correctedly saved with h2o.save_moddel def test_gam_transformed_frame_serialization(): h2o_data = h2o.import_file(