@@ -141,18 +141,18 @@ def _map_python_line_to_nb_lines(
141
141
Stdout with references to temporary Python file's lines replaced with references
142
142
to notebook's cells and lines.
143
143
"""
144
- pattern = rf"(?<={ notebook . name } :)\d+"
144
+ pattern = rf"(?<=^ { re . escape ( str ( notebook )) } :)\d+"
145
145
146
146
def substitution (match : Match [str ]) -> str :
147
147
"""Replace Python line with corresponding Jupyter notebook cell."""
148
148
return str (cell_mapping [int (match .group ())])
149
149
150
- out = re .sub (pattern , substitution , out )
150
+ out = re .sub (pattern , substitution , out , flags = re . MULTILINE )
151
151
152
152
# doctest pattern
153
- pattern = rf'(?<={ notebook . name } ", line )\d+'
154
- if re .search (pattern , out ) is not None :
155
- out = re .sub (pattern , substitution , out )
153
+ pattern = rf'(?<=^File " { re . escape ( str ( notebook )) } ", line )\d+'
154
+ if re .search (pattern , out , flags = re . MULTILINE ) is not None :
155
+ out = re .sub (pattern , substitution , out , flags = re . MULTILINE )
156
156
out = out .replace (f'{ notebook .name } ", line ' , f'{ notebook .name } ", ' )
157
157
158
158
return out
0 commit comments