From 0d7903558a6c9a622101ab5d59d7a46fbd0d7f96 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Mon, 15 Sep 2025 11:22:31 +0300 Subject: [PATCH] Fix HabanaProfile unit tests to align with idempotent start behavior --- tests/test_habana_profiler_unit.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_habana_profiler_unit.py b/tests/test_habana_profiler_unit.py index 646e604866..d334878b5a 100644 --- a/tests/test_habana_profiler_unit.py +++ b/tests/test_habana_profiler_unit.py @@ -15,6 +15,7 @@ import os import shutil +import weakref from unittest.mock import MagicMock import pytest @@ -44,7 +45,7 @@ def patched_profiler(monkeypatch): @pytest.fixture(autouse=True) def cleanup(): shutil.rmtree(PROFILER_OUTPUT_DIR, ignore_errors=True) - HabanaProfile._profilers = [] + HabanaProfile._profilers = weakref.WeakSet() def run_profiling(profiler): @@ -118,8 +119,9 @@ def test_two_profilers_can_run_sequentially(): assert len(os.listdir(PROFILER_OUTPUT_DIR)) == 2 -def test_cannot_start_profiler_when_another_is_running(patched_profiler): +def test_starting_new_profiler_stops_previous(patched_profiler): another_profiler = HabanaProfile(warmup=1, active=1) patched_profiler.start() - with pytest.raises(RuntimeError): - another_profiler.start() + another_profiler.start() + assert not patched_profiler._running + assert another_profiler._running