Skip to content

Commit 82eba44

Browse files
authored
Fix some tests on Python 3.13 RC1 (#14504)
Random little odds and ends that have changed in 3.13 break the tests. I think this should get the CI working again. 🤞 Closes #14457 Closes #14458
2 parents 78fea5f + 2e34c77 commit 82eba44

2 files changed

Lines changed: 63 additions & 50 deletions

File tree

IPython/core/tests/test_debugger.py

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -59,40 +59,43 @@ def test_ipdb_magics():
5959
6060
First, set up some test functions and classes which we can inspect.
6161
62-
>>> class ExampleClass(object):
63-
... """Docstring for ExampleClass."""
64-
... def __init__(self):
65-
... """Docstring for ExampleClass.__init__"""
66-
... pass
67-
... def __str__(self):
68-
... return "ExampleClass()"
69-
70-
>>> def example_function(x, y, z="hello"):
71-
... """Docstring for example_function."""
72-
... pass
62+
In [1]: class ExampleClass(object):
63+
...: """Docstring for ExampleClass."""
64+
...: def __init__(self):
65+
...: """Docstring for ExampleClass.__init__"""
66+
...: pass
67+
...: def __str__(self):
68+
...: return "ExampleClass()"
7369
74-
>>> old_trace = sys.gettrace()
70+
In [2]: def example_function(x, y, z="hello"):
71+
...: """Docstring for example_function."""
72+
...: pass
7573
76-
Create a function which triggers ipdb.
74+
In [3]: old_trace = sys.gettrace()
7775
78-
>>> def trigger_ipdb():
79-
... a = ExampleClass()
80-
... debugger.Pdb().set_trace()
76+
Create a function which triggers ipdb.
8177
82-
>>> with PdbTestInput([
83-
... 'pdef example_function',
84-
... 'pdoc ExampleClass',
85-
... 'up',
86-
... 'down',
87-
... 'list',
88-
... 'pinfo a',
89-
... 'll',
90-
... 'continue',
91-
... ]):
92-
... trigger_ipdb()
93-
--Return--
94-
None
95-
> <doctest ...>(3)trigger_ipdb()
78+
In [4]: def trigger_ipdb():
79+
...: a = ExampleClass()
80+
...: debugger.Pdb().set_trace()
81+
82+
Run ipdb with faked input & check output. Because of a difference between
83+
Python 3.13 & older versions, the first bit of the output is inconsistent.
84+
We need to use ... to accommodate that, so the examples have to use IPython
85+
prompts so that ... is distinct from the Python PS2 prompt.
86+
87+
In [5]: with PdbTestInput([
88+
...: 'pdef example_function',
89+
...: 'pdoc ExampleClass',
90+
...: 'up',
91+
...: 'down',
92+
...: 'list',
93+
...: 'pinfo a',
94+
...: 'll',
95+
...: 'continue',
96+
...: ]):
97+
...: trigger_ipdb()
98+
...> <doctest ...>(3)trigger_ipdb()
9699
1 def trigger_ipdb():
97100
2 a = ExampleClass()
98101
----> 3 debugger.Pdb().set_trace()
@@ -112,8 +115,7 @@ def test_ipdb_magics():
112115
10 ]):
113116
---> 11 trigger_ipdb()
114117
<BLANKLINE>
115-
ipdb> down
116-
None
118+
ipdb> down...
117119
> <doctest ...>(3)trigger_ipdb()
118120
1 def trigger_ipdb():
119121
2 a = ExampleClass()
@@ -136,10 +138,10 @@ def test_ipdb_magics():
136138
----> 3 debugger.Pdb().set_trace()
137139
<BLANKLINE>
138140
ipdb> continue
139-
140-
Restore previous trace function, e.g. for coverage.py
141-
142-
>>> sys.settrace(old_trace)
141+
142+
Restore previous trace function, e.g. for coverage.py
143+
144+
In [6]: sys.settrace(old_trace)
143145
'''
144146

145147
def test_ipdb_magics2():
@@ -495,15 +497,26 @@ def test_decorator_skip_with_breakpoint():
495497
child.expect_exact(line)
496498
child.sendline("")
497499

498-
# as the filename does not exists, we'll rely on the filename prompt
499-
child.expect_exact("47 bar(3, 4)")
500-
501-
for input_, expected in [
502-
(f"b {name}.py:3", ""),
503-
("step", "1---> 3 pass # should not stop here except"),
504-
("step", "---> 38 @pdb_skipped_decorator"),
505-
("continue", ""),
506-
]:
500+
# From 3.13, set_trace()/breakpoint() stop on the line where they're
501+
# called, instead of the next line.
502+
if sys.version_info >= (3, 13):
503+
child.expect_exact("--> 46 ipdb.set_trace()")
504+
extra_step = [("step", "--> 47 bar(3, 4)")]
505+
else:
506+
child.expect_exact("--> 47 bar(3, 4)")
507+
extra_step = []
508+
509+
for input_, expected in (
510+
[
511+
(f"b {name}.py:3", ""),
512+
]
513+
+ extra_step
514+
+ [
515+
("step", "1---> 3 pass # should not stop here except"),
516+
("step", "---> 38 @pdb_skipped_decorator"),
517+
("continue", ""),
518+
]
519+
):
507520
child.expect("ipdb>")
508521
child.sendline(input_)
509522
child.expect_exact(input_)

IPython/core/tests/test_oinspect.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,23 +516,23 @@ def prop(self, v):
516516

517517
ip.run_line_magic("pinfo", "b.prop")
518518
captured = capsys.readouterr()
519-
assert "Docstring: cdoc for prop" in captured.out
519+
assert re.search(r"Docstring:\s+cdoc for prop", captured.out)
520520

521521
ip.run_line_magic("pinfo", "b.non_exist")
522522
captured = capsys.readouterr()
523-
assert "Docstring: cdoc for non_exist" in captured.out
523+
assert re.search(r"Docstring:\s+cdoc for non_exist", captured.out)
524524

525525
ip.run_cell("b.prop?")
526526
captured = capsys.readouterr()
527-
assert "Docstring: cdoc for prop" in captured.out
527+
assert re.search(r"Docstring:\s+cdoc for prop", captured.out)
528528

529529
ip.run_cell("b.non_exist?")
530530
captured = capsys.readouterr()
531-
assert "Docstring: cdoc for non_exist" in captured.out
531+
assert re.search(r"Docstring:\s+cdoc for non_exist", captured.out)
532532

533533
ip.run_cell("b.undefined?")
534534
captured = capsys.readouterr()
535-
assert "Docstring: <no docstring>" in captured.out
535+
assert re.search(r"Type:\s+NoneType", captured.out)
536536

537537

538538
def test_pinfo_magic():

0 commit comments

Comments
 (0)