diff --git a/IPython/core/tests/test_debugger.py b/IPython/core/tests/test_debugger.py index b22be92..6113ff9 100644 --- a/IPython/core/tests/test_debugger.py +++ b/IPython/core/tests/test_debugger.py @@ -59,40 +59,43 @@ def test_ipdb_magics(): First, set up some test functions and classes which we can inspect. - >>> class ExampleClass(object): - ... """Docstring for ExampleClass.""" - ... def __init__(self): - ... """Docstring for ExampleClass.__init__""" - ... pass - ... def __str__(self): - ... return "ExampleClass()" - - >>> def example_function(x, y, z="hello"): - ... """Docstring for example_function.""" - ... pass + In [1]: class ExampleClass(object): + ...: """Docstring for ExampleClass.""" + ...: def __init__(self): + ...: """Docstring for ExampleClass.__init__""" + ...: pass + ...: def __str__(self): + ...: return "ExampleClass()" - >>> old_trace = sys.gettrace() + In [2]: def example_function(x, y, z="hello"): + ...: """Docstring for example_function.""" + ...: pass - Create a function which triggers ipdb. + In [3]: old_trace = sys.gettrace() - >>> def trigger_ipdb(): - ... a = ExampleClass() - ... debugger.Pdb().set_trace() + Create a function which triggers ipdb. - >>> with PdbTestInput([ - ... 'pdef example_function', - ... 'pdoc ExampleClass', - ... 'up', - ... 'down', - ... 'list', - ... 'pinfo a', - ... 'll', - ... 'continue', - ... ]): - ... trigger_ipdb() - --Return-- - None - > (3)trigger_ipdb() + In [4]: def trigger_ipdb(): + ...: a = ExampleClass() + ...: debugger.Pdb().set_trace() + + Run ipdb with faked input & check output. Because of a difference between + Python 3.13 & older versions, the first bit of the output is inconsistent. + We need to use ... to accommodate that, so the examples have to use IPython + prompts so that ... is distinct from the Python PS2 prompt. + + In [5]: with PdbTestInput([ + ...: 'pdef example_function', + ...: 'pdoc ExampleClass', + ...: 'up', + ...: 'down', + ...: 'list', + ...: 'pinfo a', + ...: 'll', + ...: 'continue', + ...: ]): + ...: trigger_ipdb() + ...> (3)trigger_ipdb() 1 def trigger_ipdb(): 2 a = ExampleClass() ----> 3 debugger.Pdb().set_trace() @@ -112,8 +115,7 @@ def test_ipdb_magics(): 10 ]): ---> 11 trigger_ipdb() - ipdb> down - None + ipdb> down... > (3)trigger_ipdb() 1 def trigger_ipdb(): 2 a = ExampleClass() @@ -136,10 +138,10 @@ def test_ipdb_magics(): ----> 3 debugger.Pdb().set_trace() ipdb> continue - - Restore previous trace function, e.g. for coverage.py - - >>> sys.settrace(old_trace) + + Restore previous trace function, e.g. for coverage.py + + In [6]: sys.settrace(old_trace) ''' def test_ipdb_magics2(): @@ -495,15 +497,26 @@ def test_decorator_skip_with_breakpoint(): child.expect_exact(line) child.sendline("") - # as the filename does not exists, we'll rely on the filename prompt - child.expect_exact("47 bar(3, 4)") - - for input_, expected in [ - (f"b {name}.py:3", ""), - ("step", "1---> 3 pass # should not stop here except"), - ("step", "---> 38 @pdb_skipped_decorator"), - ("continue", ""), - ]: + # From 3.13, set_trace()/breakpoint() stop on the line where they're + # called, instead of the next line. + if sys.version_info >= (3, 13): + child.expect_exact("--> 46 ipdb.set_trace()") + extra_step = [("step", "--> 47 bar(3, 4)")] + else: + child.expect_exact("--> 47 bar(3, 4)") + extra_step = [] + + for input_, expected in ( + [ + (f"b {name}.py:3", ""), + ] + + extra_step + + [ + ("step", "1---> 3 pass # should not stop here except"), + ("step", "---> 38 @pdb_skipped_decorator"), + ("continue", ""), + ] + ): child.expect("ipdb>") child.sendline(input_) child.expect_exact(input_) diff --git a/IPython/core/tests/test_oinspect.py b/IPython/core/tests/test_oinspect.py index 3decb8b..ac7c365 100644 --- a/IPython/core/tests/test_oinspect.py +++ b/IPython/core/tests/test_oinspect.py @@ -516,23 +516,23 @@ def test_pinfo_docstring_dynamic(capsys): ip.run_line_magic("pinfo", "b.prop") captured = capsys.readouterr() - assert "Docstring: cdoc for prop" in captured.out + assert re.search(r"Docstring:\s+cdoc for prop", captured.out) ip.run_line_magic("pinfo", "b.non_exist") captured = capsys.readouterr() - assert "Docstring: cdoc for non_exist" in captured.out + assert re.search(r"Docstring:\s+cdoc for non_exist", captured.out) ip.run_cell("b.prop?") captured = capsys.readouterr() - assert "Docstring: cdoc for prop" in captured.out + assert re.search(r"Docstring:\s+cdoc for prop", captured.out) ip.run_cell("b.non_exist?") captured = capsys.readouterr() - assert "Docstring: cdoc for non_exist" in captured.out + assert re.search(r"Docstring:\s+cdoc for non_exist", captured.out) ip.run_cell("b.undefined?") captured = capsys.readouterr() - assert "Docstring: " in captured.out + assert re.search(r"Type:\s+NoneType", captured.out) def test_pinfo_magic():