@@ -218,25 +218,30 @@ def test_unregister_hook(self):
218218 def test_display_stored_in_history (self ):
219219 """
220220 Test that published display data gets stored in shell history
221- for %notebook magic support.
221+ for %notebook magic support, and not stored when disabled .
222222 """
223- # Mock shell with history manager
224- mock_shell = MagicMock ()
225- mock_shell .execution_count = 1
226- mock_shell .history_manager .outputs = dict ()
227- mock_shell .display_pub ._in_post_execute = False
228-
229- self .disp_pub .shell = mock_shell
230- self .disp_pub .store_display_history = True
231-
232- data = {"text/plain" : "test output" }
233- self .disp_pub .publish (data )
234-
235- # Check that output was stored in history
236- stored_outputs = mock_shell .history_manager .outputs [1 ]
237- assert len (stored_outputs ) == 1
238- assert stored_outputs [0 ].output_type == "display_data"
239- assert stored_outputs [0 ].bundle == data
223+ for enable in [False , True ]:
224+ # Mock shell with history manager
225+ mock_shell = MagicMock ()
226+ mock_shell .execution_count = 1
227+ mock_shell .history_manager .outputs = dict ()
228+ mock_shell .display_pub ._in_post_execute = False
229+
230+ self .disp_pub .shell = mock_shell
231+ self .disp_pub .store_display_history = enable
232+
233+ data = {"text/plain" : "test output" }
234+ self .disp_pub .publish (data )
235+
236+ if enable :
237+ # Check that output was stored in history
238+ stored_outputs = mock_shell .history_manager .outputs [1 ]
239+ assert len (stored_outputs ) == 1
240+ assert stored_outputs [0 ].output_type == "display_data"
241+ assert stored_outputs [0 ].bundle == data
242+ else :
243+ # Should not store anything in history
244+ assert mock_shell .history_manager .outputs == {}
240245
241246
242247def test_magics (tmp_path ):
0 commit comments