From f07e14394c013cbd3946c94264e1d10b0887a235 Mon Sep 17 00:00:00 2001 From: skinan Date: Tue, 21 Mar 2023 12:59:38 +0000 Subject: [PATCH 1/2] clearml test issues fixed Signed-off-by: skinan --- tests/test_handler_clearml_image.py | 19 +++++++++++++++++-- tests/test_handler_clearml_stats.py | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/test_handler_clearml_image.py b/tests/test_handler_clearml_image.py index 781931327f..8e69e3bedc 100644 --- a/tests/test_handler_clearml_image.py +++ b/tests/test_handler_clearml_image.py @@ -11,22 +11,37 @@ from __future__ import annotations +import tempfile import unittest +from os import environ from monai.handlers import ClearMLImageHandler from monai.utils import optional_import Task, has_clearml = optional_import("clearml", name="Task") +get_active_config_file, has_get_active_config_file = optional_import( + "clearml.backend_config.defs", name="get_active_config_file" +) _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") @unittest.skipUnless(has_clearml, "Requires 'clearml' installation") @unittest.skipUnless(has_tb, "Requires SummaryWriter installation") -@unittest.skip("temp mute clearml tests https://github.com/Project-MONAI/MONAI/issues/6148") +@unittest.skipIf(not has_get_active_config_file, "ClearML 'get_active_config_file' not found") +# @unittest.skip("temp mute clearml tests https://github.com/Project-MONAI/MONAI/issues/6148") class TestHandlerClearMLImageHandler(unittest.TestCase): def test_task_init(self): - Task.set_offline(offline_mode=True) + handle, path = tempfile.mkstemp() + with open(handle, "w") as new_config: + with open(get_active_config_file()) as old_config: + new_config.write(old_config.read()) + new_config.write( + "\nsdk.development.vcs_repo_detect_async: false\nsdk.development.report_use_subprocess: false\n" + ) + environ["CLEARML_CONFIG_FILE"] = path try: + Task.force_store_standalone_script(True) + Task.set_offline(offline_mode=True) ClearMLImageHandler( project_name="MONAI", task_name="monai_experiment", diff --git a/tests/test_handler_clearml_stats.py b/tests/test_handler_clearml_stats.py index fad847ca1d..6bf175bf7f 100644 --- a/tests/test_handler_clearml_stats.py +++ b/tests/test_handler_clearml_stats.py @@ -11,22 +11,37 @@ from __future__ import annotations +import tempfile import unittest +from os import environ from monai.handlers import ClearMLStatsHandler from monai.utils import optional_import Task, has_clearml = optional_import("clearml", name="Task") +get_active_config_file, has_get_active_config_file = optional_import( + "clearml.backend_config.defs", name="get_active_config_file" +) _, has_tb = optional_import("torch.utils.tensorboard", name="SummaryWriter") @unittest.skipUnless(has_clearml, "Requires 'clearml' installation") @unittest.skipUnless(has_tb, "Requires SummaryWriter installation") -@unittest.skip("temp mute clearml tests https://github.com/Project-MONAI/MONAI/issues/6148") +@unittest.skipIf(not has_get_active_config_file, "ClearML 'get_active_config_file' not found") +# @unittest.skip("temp mute clearml tests https://github.com/Project-MONAI/MONAI/issues/6148") class TestHandlerClearMLStatsHandler(unittest.TestCase): def test_task_init(self): - Task.set_offline(offline_mode=True) + handle, path = tempfile.mkstemp() + with open(handle, "w") as new_config: + with open(get_active_config_file()) as old_config: + new_config.write(old_config.read()) + new_config.write( + "\nsdk.development.vcs_repo_detect_async: false\nsdk.development.report_use_subprocess: false\n" + ) + environ["CLEARML_CONFIG_FILE"] = path try: + Task.force_store_standalone_script(True) + Task.set_offline(offline_mode=True) ClearMLStatsHandler( project_name="MONAI", task_name="monai_experiment", From 0b9a64805ebc72bd6fee665222200fcfd28ec5ba Mon Sep 17 00:00:00 2001 From: skinan Date: Tue, 21 Mar 2023 14:09:13 +0000 Subject: [PATCH 2/2] clearml bug fix Signed-off-by: skinan --- tests/test_handler_clearml_image.py | 5 +++-- tests/test_handler_clearml_stats.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_handler_clearml_image.py b/tests/test_handler_clearml_image.py index 8e69e3bedc..9f9d0687aa 100644 --- a/tests/test_handler_clearml_image.py +++ b/tests/test_handler_clearml_image.py @@ -33,8 +33,9 @@ class TestHandlerClearMLImageHandler(unittest.TestCase): def test_task_init(self): handle, path = tempfile.mkstemp() with open(handle, "w") as new_config: - with open(get_active_config_file()) as old_config: - new_config.write(old_config.read()) + if get_active_config_file(): + with open(get_active_config_file()) as old_config: + new_config.write(old_config.read()) new_config.write( "\nsdk.development.vcs_repo_detect_async: false\nsdk.development.report_use_subprocess: false\n" ) diff --git a/tests/test_handler_clearml_stats.py b/tests/test_handler_clearml_stats.py index 6bf175bf7f..5fc0720a4e 100644 --- a/tests/test_handler_clearml_stats.py +++ b/tests/test_handler_clearml_stats.py @@ -33,8 +33,9 @@ class TestHandlerClearMLStatsHandler(unittest.TestCase): def test_task_init(self): handle, path = tempfile.mkstemp() with open(handle, "w") as new_config: - with open(get_active_config_file()) as old_config: - new_config.write(old_config.read()) + if get_active_config_file(): + with open(get_active_config_file()) as old_config: + new_config.write(old_config.read()) new_config.write( "\nsdk.development.vcs_repo_detect_async: false\nsdk.development.report_use_subprocess: false\n" )