diff --git a/tests/test_utils_get_adj.py b/tests/test_utils_get_adj.py index 5e7672683..9718a8a7b 100644 --- a/tests/test_utils_get_adj.py +++ b/tests/test_utils_get_adj.py @@ -5,11 +5,28 @@ from slic.core.adjustable import Adjustable sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from slic.utils.get_adj import * -@pytest.fixture(autouse=True) -def cleanup_adjustables(): - instances(Adjustable, weak=True).clear() - yield - instances(Adjustable, weak=True).clear() +def unregister_adj(target): + weak_set = instances(Adjustable, weak=True) + removed = 0 + + # Normaliser en liste + targets = target if isinstance(target, (list, tuple, set)) else [target] + + for item in targets: + if isinstance(item, Adjustable): + if item in weak_set: + weak_set.discard(item) + removed += 1 + elif isinstance(item, str): + to_remove = [obj for obj in weak_set if obj.name == item] + for obj in to_remove: + weak_set.discard(obj) + removed += len(to_remove) + else: + raise TypeError("target must be Adjustable, str, or iterable thereof") + + return removed + class SubAdjustable(Adjustable): def __init__(self, *a, **kw): @@ -37,6 +54,7 @@ def real_adjustables(): def test_get_adj_success(real_adjustables): a1, _, _ = real_adjustables assert get_adj("brightness") is a1 + unregister_adj([a1, a1, a3]) def test_get_adj_not_found(capfd): @@ -48,6 +66,7 @@ def test_ensure_adjs_mixed(real_adjustables): a1, a2, a3 = real_adjustables result = ensure_adjs(["contrast", a1, "debug_internal"]) assert result == (a2, a1, a3) + unregister_adj([a1, a1, a3]) def test_get_adjs_filter(real_adjustables): @@ -56,3 +75,4 @@ def test_get_adjs_filter(real_adjustables): assert public == {"brightness": a1, "contrast": a2} all_ = get_adjs(include_internal=True) assert all_ == {"brightness": a1, "contrast": a2, "debug_internal": a3} + unregister_adj([a1, a1, a3])