From 3554706b83e20ce3771b07a6402ef818edc865bb 2020-07-18 20:34:58 From: Matthias Bussonnier Date: 2020-07-18 20:34:58 Subject: [PATCH] Merge pull request #12453 from impact27/patch-5 --- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index effedbd..c6cf082 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -451,7 +451,13 @@ class ExecutionMagics(Magics): if not (args.breakpoint or args.statement or cell): self._debug_post_mortem() + elif not (args.breakpoint or cell): + # If there is no breakpoints, the line is just code to execute + self._debug_exec(line, None) else: + # Here we try to reconstruct the code from the output of + # parse_argstring. This might not work if the code has spaces + # For example this fails for `print("a b")` code = "\n".join(args.statement) if cell: code += "\n" + cell diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 56feb82..a52ab02 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -32,6 +32,7 @@ from IPython.utils.io import capture_output from IPython.utils.tempdir import (TemporaryDirectory, TemporaryWorkingDirectory) from IPython.utils.process import find_cmd +from .test_debugger import PdbTestInput @magic.magics_class @@ -599,6 +600,18 @@ def doctest_precision(): Out[5]: '3.141593e+00' """ +def test_debug_magic(): + """Test debugging a small code with %debug + + In [1]: with PdbTestInput(['c']): + ...: %debug print("a b") #doctest: +ELLIPSIS + ...: + ... + ipdb> c + a b + In [2]: + """ + def test_psearch(): with tt.AssertPrints("dict.fromkeys"): _ip.run_cell("dict.fr*?")