Open
Description
Description
This is a pending refactoring suggested in PR #210. We postponed it to close the PR fast. There is no functional impact, it only reduces the code complexity.
(In file test/test_remote_access.py
~ L136)
To avoid using hasattr
and setting up your own temporary urls, instead of a per test setup/tear-down, I'd use one for the whole class.
- In the
setupClass
method you simply set the env varKHIOPS_TMP_DIR
with a fresh runner. - In the
tearDownClass
method you clean up everything and restore the original temporary directory and runner.
Something like this example
import unittest
import os
import subprocess
from khiops import core as kh
from khiops.core.internals.runner import KhiopsLocalRunner
class TestWithAltRunner(unittest.TestCase):
@classmethod
def setUpClass(cls):
# Save the original runner and temp dir
cls.original_runner = kh.get_runner()
cls.original_khiops_temp_dir = os.environ.get("KHIOPS_TMP_DIR")
# Set the test suite temp dir
os.environ["KHIOPS_TMP_DIR"] = "/tmp/mytmpdir/" # replace here with the URL
cls.runner = KhiopsLocalRunner()
@classmethod
def tearDownClass(cls):
# Restore the original runner and temp dir
kh.set_runner(cls.original_runner)
if cls.original_khiops_temp_dir is None:
del os.environ["KHIOPS_TMP_DIR"]
else:
os.environ["KHIOPS_TMP_DIR"] = cls.original_khiops_temp_dir
# Clean the whole alternative temporary file
# ...
def test(self):
print("\n======= Current test runner =========")
kh.get_runner().print_status()
Originally posted by @folmos-at-orange in #210 (comment)