Skip to content

Refactor integration tests #328

Open
@folmos-at-orange

Description

@folmos-at-orange

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 var KHIOPS_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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Size/DaysSome days of workStatus/ReadyForDevThe issue is ready to be developed or to be investigated deeply

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions