Skip to content

Commit

Permalink
Merge pull request #3173 from jtpio/close-all
Browse files Browse the repository at this point in the history
Fix the use of _active_widgets in Widget.close_all()
  • Loading branch information
ianhi authored Apr 1, 2021
2 parents 624dfc8 + 3f8ae83 commit c9afb4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ipywidgets/widgets/tests/test_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit c9afb4b

Please sign in to comment.