diff --git a/ipywidgets/widgets/tests/test_widget.py b/ipywidgets/widgets/tests/test_widget.py index c6f2f3cd66..7a70b82c3b 100644 --- a/ipywidgets/widgets/tests/test_widget.py +++ b/ipywidgets/widgets/tests/test_widget.py @@ -43,3 +43,15 @@ def test_widget_view(): assert 'application/vnd.jupyter.widget-view+json' in mime_bundle, "widget should have have a view" assert cap.stdout == '', repr(cap.stdout) assert cap.stderr == '', repr(cap.stderr) + + +def test_close_all(): + # create a couple of widgets + widgets = [Button() for i in range(10)] + + assert len(Widget._active_widgets) > 0, "expect active widgets" + + # close all the widgets + Widget.close_all() + + assert len(Widget._active_widgets) == 0, "active widgets should be cleared" diff --git a/ipywidgets/widgets/widget.py b/ipywidgets/widgets/widget.py index 4b495b9c50..72310cd0dd 100644 --- a/ipywidgets/widgets/widget.py +++ b/ipywidgets/widgets/widget.py @@ -271,7 +271,7 @@ class Widget(LoggingHasTraits): @classmethod def close_all(cls): - for widget in list(cls.widgets.values()): + for widget in list(cls._active_widgets.values()): widget.close()