Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the use of _active_widgets in Widget.close_all() #3173

Merged
merged 3 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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