Skip to content

Commit

Permalink
Merge pull request #23477 from ccordoba12/filter-traceback-frames
Browse files Browse the repository at this point in the history
PR: Filter frames that come from Spyder-kernels in tracebacks and fix tracebacks in Python 3.8 (IPython console)
  • Loading branch information
ccordoba12 authored Jan 17, 2025
2 parents 1e20d17 + d25e9d2 commit da7fc96
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions external-deps/spyder-kernels/.gitrepo

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions external-deps/spyder-kernels/RELEASE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 40 additions & 9 deletions external-deps/spyder-kernels/spyder_kernels/console/shell.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -2449,5 +2449,60 @@ def test_floats_selected_on_double_click(ipyconsole, qtbot):
assert control.get_selected_text() == float_number


def test_filter_frames_in_tracebacks(ipyconsole, qtbot, tmp_path):
"""Check that we filter some unnecessary frames in tracebacks."""
# Wait until the window is fully up
shell = ipyconsole.get_current_shellwidget()
control = shell._control
qtbot.waitUntil(
lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT
)

# Write code to file
file = tmp_path / 'test_filter_frames.py'
file.write_text("# Comment\n1/0")

# Filename in the format used when running magics from the main toolbar
fname = str(file).replace('\\', '/')

# Run file
with qtbot.waitSignal(shell.executed):
shell.execute(f"%runfile {fname}")

# Check frames related to spyder-kernels are not displayed
assert "spyder_kernels" not in control.toPlainText()

# Switch to %xmode plain and check again
with qtbot.waitSignal(shell.executed):
shell.execute("%xmode plain")

with qtbot.waitSignal(shell.executed):
shell.execute(f"%runfile {fname}")

assert "spyder_kernels" not in control.toPlainText()

# Switch back to %xmode verbose (the default)
with qtbot.waitSignal(shell.executed):
shell.execute("%xmode verbose")

# Check we don't display a traceback when exiting our debugger if it's
# started with breakpoint().
file.write_text("# Comment\nbreakpoint()")
with qtbot.waitSignal(shell.executed):
shell.execute(f"%runfile {fname}")

shell.clear_console()
empty_console_text = (
"\n\nIPdb [2]: " if os.name == "nt" else "\nIPdb [2]: "
)
qtbot.waitUntil(lambda: empty_console_text == control.toPlainText())

with qtbot.waitSignal(shell.executed):
qtbot.keyClicks(control, '!exit')
qtbot.keyClick(control, Qt.Key_Enter)

assert "BdbQuit" not in control.toPlainText()


if __name__ == "__main__":
pytest.main()

0 comments on commit da7fc96

Please sign in to comment.