diff --git a/spyder/plugins/outlineexplorer/tests/test_widgets.py b/spyder/plugins/outlineexplorer/tests/test_widgets.py index 54ab7d741d3..637fe6c5df4 100644 --- a/spyder/plugins/outlineexplorer/tests/test_widgets.py +++ b/spyder/plugins/outlineexplorer/tests/test_widgets.py @@ -217,6 +217,37 @@ def test_go_to_last_item(create_outlineexplorer, qtbot): assert outlineexplorer.treewidget.currentItem().text(0) == 'method1' +@flaky(max_runs=10) +def test_display_variables(create_outlineexplorer, qtbot): + """ + Test that clicking on the 'Display variables and attributes' button located in the + toolbar of the outline explorer is working as expected by updating the tree widget. + + Regression test for spyder-ide/spyder#21456. + """ + outlineexplorer, _ = create_outlineexplorer('text') + + editor = outlineexplorer.treewidget.current_editor + state = outlineexplorer.treewidget.display_variables + + editor_id = editor.get_id() + + initial_tree = outlineexplorer.treewidget.editor_tree_cache[editor_id] + + outlineexplorer.treewidget.toggle_variables(not state) + + first_toggle_tree = outlineexplorer.treewidget.editor_tree_cache[editor_id] + + assert first_toggle_tree != initial_tree + + outlineexplorer.treewidget.toggle_variables(state) + + second_toggle_tree = outlineexplorer.treewidget.editor_tree_cache[editor_id] + + assert (second_toggle_tree != first_toggle_tree) and ( + second_toggle_tree == initial_tree) + + if __name__ == "__main__": import os pytest.main(['-x', os.path.basename(__file__), '-v', '-rw']) diff --git a/spyder/plugins/outlineexplorer/widgets.py b/spyder/plugins/outlineexplorer/widgets.py index 925779412e4..d31fb682a2d 100644 --- a/spyder/plugins/outlineexplorer/widgets.py +++ b/spyder/plugins/outlineexplorer/widgets.py @@ -608,8 +608,7 @@ def update_tree(self, items, editor): if not must_update: # Compare with current tree to check if it's necessary to update # it. - changes = tree - current_tree - if tree and len(changes) == 0: + if tree == current_tree: logger.debug( f"Current and new trees for file {editor.fname} are the " f"same, so no update is necessary"