Skip to content

Commit 455205e

Browse files
frenzymadnessdevintang3
authored andcommitted
Compatibility with IPython 8 where tracebacks are different
1 parent eb3e8fa commit 455205e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

nbclient/tests/test_client.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@
2727
from .base import NBClientTestsBase
2828

2929
addr_pat = re.compile(r'0x[0-9a-f]{7,9}')
30-
ipython_input_pat = re.compile(r'<ipython-input-\d+-[0-9a-f]+>')
3130
current_dir = os.path.dirname(__file__)
31+
ipython_input_pat = re.compile(r'<ipython-input-\d+-[0-9a-f]+>')
32+
# Tracebacks look different in IPython 8,
33+
# see: https://github.com/ipython/ipython/blob/master/docs/source/whatsnew/version8.rst#traceback-improvements # noqa
34+
ipython8_input_pat = re.compile(r'Input In \[\d+\],')
3235

3336

3437
class AsyncMock(Mock):
@@ -201,10 +204,11 @@ def normalize_output(output):
201204
if isinstance(value, string_types):
202205
output['data'][key] = normalize_base64(value)
203206
if 'traceback' in output:
204-
tb = [
205-
re.sub(ipython_input_pat, '<IPY-INPUT>', strip_ansi(line))
206-
for line in output['traceback']
207-
]
207+
tb = []
208+
for line in output["traceback"]:
209+
line = re.sub(ipython_input_pat, '<IPY-INPUT>', strip_ansi(line))
210+
line = re.sub(ipython8_input_pat, '<IPY-INPUT>', strip_ansi(line))
211+
tb.append(line)
208212
output['traceback'] = tb
209213

210214
return output

0 commit comments

Comments
 (0)