3
3
4
4
Authors: D. Cortes, O. Laslett
5
5
6
- For now, install pytest-ipynb plugin (
7
- https://github.com/zonca/pytest-ipynb ) :
8
-
9
- sudo pip install pytest-ipynb
10
-
11
- And replace the file with:
12
-
13
- sudo cp pytest_plugin.py /usr/local/lib/python2.7/dist-packages/pytest_ipynb/plugin.py
14
-
15
6
"""
16
7
17
8
import pytest
@@ -162,6 +153,7 @@ def teardown(self):
162
153
self .kernel .stop ()
163
154
164
155
156
+
165
157
class IPyNbCell (pytest .Item ):
166
158
def __init__ (self , name , parent , cell_num , cell ):
167
159
super (IPyNbCell , self ).__init__ (name , parent )
@@ -172,13 +164,31 @@ def __init__(self, name, parent, cell_num, cell):
172
164
#
173
165
self .comparisons = None
174
166
167
+
168
+ """ *****************************************************
169
+ ***************** TESTING FUNCTIONS ***************
170
+ ***************************************************** """
171
+
172
+ def repr_failure (self , excinfo ):
173
+ """ called when self.runtest() raises an exception. """
174
+ if isinstance (excinfo .value , NbCellError ):
175
+ return "\n " .join ([
176
+ "Notebook execution failed" ,
177
+ "Cell %d: %s\n \n "
178
+ "Input:\n %s\n \n "
179
+ "Traceback:\n %s\n " % excinfo .value .args ,
180
+ ])
181
+ else :
182
+ return "pytest plugin exception: %s" % str (excinfo .value )
183
+
184
+ def reportinfo (self ):
185
+ description = "cell %d" % self .cell_num
186
+ return self .fspath , 0 , description
187
+
175
188
def compare_outputs (self , test , ref , skip_compare = ('png' ,
176
189
'traceback' ,
177
190
'latex' ,
178
191
'prompt_number' )):
179
- """
180
-
181
- """
182
192
self .comparisons = []
183
193
184
194
for key in ref :
@@ -215,26 +225,10 @@ def compare_outputs(self, test, ref, skip_compare=('png',
215
225
return False
216
226
return True
217
227
228
+ """ *****************************************************
229
+ ***************************************************** """
218
230
219
231
220
- """ TESTING FUNCTIONS """
221
-
222
- def repr_failure (self , excinfo ):
223
- """ called when self.runtest() raises an exception. """
224
- if isinstance (excinfo .value , NbCellError ):
225
- return "\n " .join ([
226
- "Notebook execution failed" ,
227
- "Cell %d: %s\n \n "
228
- "Input:\n %s\n \n "
229
- "Traceback:\n %s\n " % excinfo .value .args ,
230
- ])
231
- else :
232
- return "pytest plugin exception: %s" % str (excinfo .value )
233
-
234
- def reportinfo (self ):
235
- description = "cell %d" % self .cell_num
236
- return self .fspath , 0 , description
237
-
238
232
def runtest (self ):
239
233
"""
240
234
Run all the cell tests in one kernel without restarting.
@@ -282,19 +276,13 @@ def runtest(self):
282
276
# print msg['content']
283
277
# print msg['msg_type']
284
278
285
- # Breaks on the last message
286
- # This is useful when no piece of code is left to be executed
287
- # in acell. It doesnt work well for us
288
- # if (msg.get("parent_header", None) and
289
- # msg["parent_header"].get("msg_id", None) == msg_id):
290
- # break
291
279
except Empty :
292
280
# This is not working: ! The code will not be checked
293
281
# if the time is out (when the cell stops to be executed?)
294
282
# raise NbCellError("Timeout of %d seconds exceeded"
295
283
# " executing cell: %s" (timeout,
296
284
# self.cell.input))
297
- # This is better: Just break the loop when the output is empty
285
+ # Just break the loop when the output is empty
298
286
break
299
287
300
288
"""
@@ -398,14 +386,6 @@ def runtest(self):
398
386
if not self .compare_outputs (out , ref ):
399
387
failed = True
400
388
401
- # if failed:
402
- # failures += 1
403
- # else:
404
- # successes += 1
405
- # sys.stdout.write('.')
406
-
407
- # raise NotImplementedError
408
-
409
389
# if reply['status'] == 'error':
410
390
# Traceback is only when an error is raised (?)
411
391
0 commit comments