Skip to content

Commit 7d9ddbf

Browse files
committed
Update tests to verify no interference
1 parent b988e6f commit 7d9ddbf

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

Lib/test/test_pyrepl/test_interact.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,21 +346,23 @@ def fake_multiline_input(more_lines, ps1, ps2):
346346
stack.enter_context(contextlib.redirect_stderr(output))
347347
run_multiline_interactive_console(console)
348348

349-
return output.getvalue()
349+
return output.getvalue(), console.locals
350350

351351
def test_hook_called_with_statement(self):
352352
hook = MagicMock()
353353
self._run_interactive(["x = 1"], pre_execution_hook=hook)
354354
hook.assert_called_once_with("x = 1")
355355

356356
def test_hook_exception_does_not_break_repl(self):
357-
def bad_hook(command):
358-
raise RuntimeError("hook error")
359-
360-
self._run_interactive(
357+
hook = MagicMock(side_effect=RuntimeError("hook error"))
358+
output, namespace = self._run_interactive(
361359
["x = 1", "y = 2"],
362-
pre_execution_hook=bad_hook,
360+
pre_execution_hook=hook,
363361
)
362+
self.assertEqual(hook.call_count, 2)
363+
self.assertEqual(namespace["x"], 1)
364+
self.assertEqual(namespace["y"], 2)
365+
self.assertNotIn("hook error", output)
364366

365367
def test_hook_not_called_for_repl_commands(self):
366368
hook = MagicMock()

0 commit comments

Comments
 (0)