Skip to content

Commit 0c1d5e6

Browse files
authored
Merge pull request #539 from KhiopsML/fix-tests
2 parents d52d4e8 + da7d95a commit 0c1d5e6

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
- Example: 10.2.1.4 is the 5th version that supports khiops 10.2.1.
77
- Internals: Changes in *Internals* sections are unlikely to be of interest for data scientists.
88

9-
## 11.0.0.2 - 2026-01-23
9+
## 11.0.0.2 - 2026-01-26
1010

1111
## Fixed
1212
- (`core`) Samples dir path construction when HOME is a remote path

tests/test_remote_access.py

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def setUp(self):
149149
)
150150
self.print_test_title()
151151

152+
# Save the runner that can be modified by the test
153+
self.initial_runner = kh.get_runner()
154+
152155
def tearDown(self):
153156
# Cleanup the output dir (the files within and the folder)
154157
if hasattr(self, "folder_name_to_clean_in_teardown"):
@@ -160,6 +163,25 @@ def tearDown(self):
160163
)
161164
fs.remove(self.folder_name_to_clean_in_teardown)
162165

166+
# Restore the environment variables that can be left tained
167+
# after a test failure
168+
if hasattr(self, "env_vars_to_restore"):
169+
for var_name in self.env_vars_to_restore:
170+
# Delete 'var_name' from the environment if it was not
171+
# in the environment at the beginning of each test
172+
if (
173+
self.env_vars_to_restore[var_name] is None
174+
and os.environ.get(var_name) is not None
175+
):
176+
del os.environ[var_name]
177+
# Set 'var_name' in the environment to the value it had
178+
# before the beginning of each test
179+
elif self.env_vars_to_restore.get(var_name) is not None:
180+
os.environ[var_name] = self.env_vars_to_restore[var_name]
181+
182+
# Reset the current runner to the value it had before each test
183+
kh.set_runner(self.initial_runner)
184+
163185
def test_train_predictor_with_remote_access(self):
164186
"""Test train_predictor with remote resources"""
165187
iris_data_dir = fs.get_child_path(kh.get_runner().samples_dir, "Iris")
@@ -227,16 +249,27 @@ def test_train_predictor_fail_and_log_with_remote_access(self):
227249
self.assertTrue(fs.exists(log_file_path), f"Path: {log_file_path}")
228250
fs.remove(log_file_path)
229251

252+
@unittest.skipIf(
253+
docker_runner_config_exists(),
254+
"Skip the remote path tests for docker runner",
255+
)
230256
def test_samples_dir_inferred_from_remote_home(self):
231257
"""Test samples_dir is correctly inferred using a remote path in HOME"""
232258

233-
# Save initial state
234-
# This runner has remote paths (for root_temp_dir for example)
235-
initial_runner = kh.get_runner()
236-
initial_home = os.environ.get("HOME")
237-
238-
# Set a remote path to HOME
239-
os.environ["HOME"] = initial_runner.root_temp_dir
259+
# Save the changed env vars in a dict that will be restored by tearDown
260+
# even if the test fails
261+
self.env_vars_to_restore = {}
262+
for var_name in ("HOME", "KHIOPS_SAMPLES_DIR"):
263+
print(f"Initial value of {var_name} = {os.environ.get(var_name)}")
264+
self.env_vars_to_restore[var_name] = os.environ.get(var_name)
265+
266+
# The current runner kh.get_runner() has remote paths
267+
# (in root_temp_dir attribute for example)
268+
# Set this remote path to HOME
269+
os.environ["HOME"] = kh.get_runner().root_temp_dir
270+
# Delete KHIOPS_SAMPLES_DIR so that its value will be inferred using HOME
271+
if os.environ.get("KHIOPS_SAMPLES_DIR") is not None:
272+
del os.environ["KHIOPS_SAMPLES_DIR"]
240273
test_runner = KhiopsLocalRunner()
241274
kh.set_runner(test_runner)
242275

@@ -249,11 +282,6 @@ def test_samples_dir_inferred_from_remote_home(self):
249282
)
250283
self.assertEqual(test_runner.samples_dir, expected_samples_dir)
251284

252-
# Restore initial state
253-
if initial_home is not None:
254-
os.environ["HOME"] = initial_home
255-
kh.set_runner(initial_runner)
256-
257285

258286
class KhiopsS3RemoteFileTests(KhiopsRemoteAccessTestsContainer.KhiopsRemoteAccessTests):
259287
"""Integration tests with Amazon S3 filesystems"""

0 commit comments

Comments
 (0)