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

[WIP] PR: Add post_mortem to runcell calls for "run current cell" action #19611

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3899,6 +3899,39 @@ def test_post_mortem(main_window, qtbot, tmpdir):
assert "IPdb [" in control.toPlainText()


# @pytest.mark.slow
@flaky(max_runs=3)
@pytest.mark.parametrize("post_mortem", [True, False])
def test_post_mortem_run_cell(main_window, qtbot, tmpdir, post_mortem):
"""Test post mortem works"""
# Check we can use custom complete for pdb
shell = main_window.ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)
control = main_window.ipyconsole.get_widget().get_focus_widget()

test_file = tmpdir.join('test.py')
test_file.write('raise RuntimeError\n')

# Load code in the editor
main_window.editor.load(to_text_string(test_file))

CONF.set('run', 'post_mortem', post_mortem)

# Wait for the console to be up
shell = main_window.ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Run a cell
with qtbot.waitSignal(shell.executed):
run_cell_action = main_window.run_toolbar_actions[1]
run_cell_button = main_window.run_toolbar.widgetForAction(run_cell_action)
qtbot.mouseClick(run_cell_button, Qt.LeftButton)

assert ("IPdb [" in control.toPlainText()) is post_mortem


@pytest.mark.slow
@flaky(max_runs=3)
def test_run_unsaved_file_multiprocessing(main_window, qtbot):
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/editor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Editor(SpyderPluginWidget, SpyderConfigurationObserver):
# Signals
sig_run_file_in_ipyclient = Signal(
str, str, str, bool, bool, bool, bool, bool, str, bool)
sig_run_cell_in_ipyclient = Signal(str, object, str, bool, str, bool)
sig_run_cell_in_ipyclient = Signal(str, object, str, bool, str, bool, bool)

exec_in_extconsole = Signal(str, bool)
redirect_stdio = Signal(bool)
Expand Down
5 changes: 3 additions & 2 deletions spyder/plugins/editor/widgets/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class EditorStack(QWidget):
ending_long_process = Signal(str)
redirect_stdio = Signal(bool)
exec_in_extconsole = Signal(str, bool)
sig_run_cell_in_ipyclient = Signal(str, object, str, bool, str, bool)
sig_run_cell_in_ipyclient = Signal(str, object, str, bool, str, bool, bool)
update_plugin_title = Signal()
editor_focus_changed = Signal()
zoom_in = Signal()
Expand Down Expand Up @@ -2913,9 +2913,10 @@ def _run_cell_text(self, text, editor, cell_id, method=None):
run_cell_copy = self.run_cell_copy
if method != "runcell":
run_cell_copy = False
post_mortem = CONF.get('run', 'post_mortem', False)
self.sig_run_cell_in_ipyclient.emit(
text, cell_name, filename, run_cell_copy, method,
self.focus_to_editor)
self.focus_to_editor, post_mortem)

# ------ Drag and drop
def dragEnterEvent(self, event):
Expand Down
7 changes: 5 additions & 2 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def run_script(self, filename, wdir, args='',
force_wdir)

def run_cell(self, code, cell_name, filename, run_cell_copy,
method='runcell', focus_to_editor=False):
method='runcell', focus_to_editor=False, post_mortem=False):
"""
Run cell in current or dedicated client.

Expand All @@ -631,6 +631,9 @@ def run_cell(self, code, cell_name, filename, run_cell_copy,
focus_to_editor: bool
Whether to give focus to the editor after running the cell. If
False, focus is given to the console.
post_mortem : bool, optional
True if in case of error the execution should enter in
post-mortem mode, False otherwise.

Returns
-------
Expand All @@ -639,7 +642,7 @@ def run_cell(self, code, cell_name, filename, run_cell_copy,
self.sig_unmaximize_plugin_requested.emit()
self.get_widget().run_cell(
code, cell_name, filename, run_cell_copy, method=method,
focus_to_editor=focus_to_editor)
focus_to_editor=focus_to_editor, post_mortem=post_mortem)

def execute_code(self, lines, current_client=True, clear_variables=False):
"""
Expand Down
7 changes: 4 additions & 3 deletions spyder/plugins/ipythonconsole/widgets/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ def interrupt_kernel(self):

# ---- For cells
def run_cell(self, code, cell_name, filename, run_cell_copy,
method='runcell', focus_to_editor=False):
method='runcell', focus_to_editor=False, post_mortem=False):
"""Run cell in current or dedicated client."""

def norm(text):
Expand All @@ -1777,10 +1777,11 @@ def norm(text):
elif is_spyder_kernel:
# Use custom function
line = (str(
"{}({}, '{}')").format(
"{}({}, '{}', post_mortem={})").format(
str(method),
repr(cell_name),
norm(filename).replace("'", r"\'")))
norm(filename).replace("'", r"\'"),
post_mortem is True))

if method == "debugcell":
# To keep focus in editor after running debugfile
Expand Down