From 644f1031f6ff27064111565b0882cb8b2544aa2f Mon Sep 17 00:00:00 2001 From: wyzula-jan <133381102+wyzula-jan@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:27:22 +0100 Subject: [PATCH] fix(tests): BECDispatcher fixture putted back --- tests/conftest.py | 70 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b732950a..009d97fb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,35 +1,35 @@ -# import pytest -# import threading -# -# from bec_lib.bec_service import BECService -# from bec_widgets.utils import bec_dispatcher as bec_dispatcher_module -# -# -# @pytest.fixture() -# def threads_check(): -# current_threads = set( -# th -# for th in threading.enumerate() -# if "loguru" not in th.name and th is not threading.main_thread() -# ) -# yield -# threads_after = set( -# th -# for th in threading.enumerate() -# if "loguru" not in th.name and th is not threading.main_thread() -# ) -# additional_threads = threads_after - current_threads -# assert ( -# len(additional_threads) == 0 -# ), f"Test creates {len(additional_threads)} threads that are not cleaned: {additional_threads}" -# -# -# @pytest.fixture(autouse=True) -# def bec_dispatcher(threads_check): -# bec_dispatcher = bec_dispatcher_module.BECDispatcher() -# yield bec_dispatcher -# bec_dispatcher.disconnect_all() -# # clean BEC client -# BECService.shutdown(bec_dispatcher.client) -# # reinitialize singleton for next test -# bec_dispatcher_module._bec_dispatcher = None +import pytest +import threading + +from bec_lib.bec_service import BECService +from bec_widgets.utils import bec_dispatcher as bec_dispatcher_module + + +@pytest.fixture() +def threads_check(): + current_threads = set( + th + for th in threading.enumerate() + if "loguru" not in th.name and th is not threading.main_thread() + ) + yield + threads_after = set( + th + for th in threading.enumerate() + if "loguru" not in th.name and th is not threading.main_thread() + ) + additional_threads = threads_after - current_threads + assert ( + len(additional_threads) == 0 + ), f"Test creates {len(additional_threads)} threads that are not cleaned: {additional_threads}" + + +@pytest.fixture(autouse=True) +def bec_dispatcher(threads_check): + bec_dispatcher = bec_dispatcher_module.BECDispatcher() + yield bec_dispatcher + bec_dispatcher.disconnect_all() + # clean BEC client + BECService.shutdown(bec_dispatcher.client) + # reinitialize singleton for next test + bec_dispatcher_module._bec_dispatcher = None