Skip to content

Commit c2bfb9e

Browse files
committed
test: mock get_ipython_execution_count directly in unit tests
1 parent d6b1bc1 commit c2bfb9e

2 files changed

Lines changed: 5 additions & 13 deletions

File tree

packages/bigframes/tests/unit/display/test_anywidget.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,10 @@ def test_page_size_change_resets_sort(mock_df):
180180
def test_cell_execution_count_propagation(mock_df):
181181
"""Test that the captured cell_execution_count is propagated to to_pandas_batches."""
182182
with mock.patch(
183-
"IPython.core.interactiveshell.InteractiveShell.initialized", return_value=True
183+
"bigframes.core.utils.get_ipython_execution_count", return_value=42
184184
):
185-
with mock.patch(
186-
"IPython.core.interactiveshell.InteractiveShell.instance"
187-
) as mock_instance:
188-
mock_instance.return_value.execution_count = 42
189-
with bigframes.option_context("display.render_mode", "anywidget"):
190-
widget = TableWidget(mock_df)
185+
with bigframes.option_context("display.render_mode", "anywidget"):
186+
widget = TableWidget(mock_df)
191187

192188
assert widget._cell_execution_count == 42
193189

packages/bigframes/tests/unit/session/test_read_gbq_colab.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,9 @@ def test_execution_history_filters_by_notebook_cell_when_all_cells_is_false():
208208
session._metrics.jobs.extend([job1, job2])
209209

210210
with mock.patch(
211-
"IPython.core.interactiveshell.InteractiveShell.initialized", return_value=True
211+
"bigframes.core.utils.get_ipython_execution_count", return_value=20
212212
):
213-
with mock.patch(
214-
"IPython.core.interactiveshell.InteractiveShell.instance"
215-
) as mock_instance:
216-
mock_instance.return_value.execution_count = 20
217-
history = session.execution_history(all_cells=False).to_dataframe()
213+
history = session.execution_history(all_cells=False).to_dataframe()
218214

219215
assert len(history) == 1
220216
assert history.iloc[0]["job_id"] == "job_2"

0 commit comments

Comments
 (0)