@@ -104,7 +104,7 @@ def pytest_addoption(parser):
104
104
help = '(deprecated) Alias of --nbval-sanitize-with' )
105
105
106
106
group .addoption ('--current-env' , action = 'store_true' ,
107
- help = '(deprecated) Alias of --nbval-current-env' )
107
+ help = '(deprecated) Alias of --nbval-current-env' )
108
108
109
109
term_group = parser .getgroup ("terminal reporting" )
110
110
term_group ._addoption (
@@ -150,6 +150,7 @@ def pytest_collect_file(path, parent):
150
150
comment_markers = {
151
151
'PYTEST_VALIDATE_IGNORE_OUTPUT' : ('check' , False ), # For backwards compatibility
152
152
'NBVAL_IGNORE_OUTPUT' : ('check' , False ),
153
+ 'NBVAL_TEST_NAME' : ('name' , str ),
153
154
'NBVAL_CHECK_OUTPUT' : 'check' ,
154
155
'NBVAL_RAISES_EXCEPTION' : 'check_exception' ,
155
156
'NBVAL_SKIP' : 'skip' ,
@@ -173,14 +174,22 @@ def find_comment_markers(cellsource):
173
174
line = line .strip ()
174
175
if line .startswith ('#' ):
175
176
# print("Found comment in '{}'".format(line))
176
- comment = line .lstrip ('#' ).strip ()
177
+ comment_val = line .lstrip ('#' ).strip ()
178
+ if ':' in comment_val :
179
+ comment , val = comment_val .split (':' , 1 )
180
+ comment = comment .rstrip ()
181
+ val = val .lstrip ()
182
+ else :
183
+ comment = comment_val
177
184
if comment in comment_markers :
178
185
# print("Found marker {}".format(comment))
179
186
marker = comment_markers [comment ]
180
187
if not isinstance (marker , tuple ):
181
188
# If not an explicit tuple ('option', True/False),
182
189
# imply ('option', True)
183
190
marker = (marker , True )
191
+ elif marker [1 ] is str :
192
+ marker = (marker [0 ], val )
184
193
marker_type = marker [0 ]
185
194
if marker_type in found :
186
195
warnings .warn (
@@ -267,7 +276,7 @@ def setup(self):
267
276
self .kernel = RunningKernel (
268
277
kernel_name ,
269
278
cwd = str (self .fspath .dirname ),
270
- startup_timeout = self .config .option .nbval_kernel_startup_timeout ,
279
+ startup_timeout = self .config .option .nbval_kernel_startup_timeout ,
271
280
)
272
281
self .setup_sanitize_files ()
273
282
if getattr (self .parent .config .option , 'cov_source' , None ):
@@ -327,6 +336,8 @@ def collect(self):
327
336
with warnings .catch_warnings (record = True ) as ws :
328
337
options = defaultdict (bool , find_metadata_tags (cell .metadata ))
329
338
comment_opts = dict (find_comment_markers (cell .source ))
339
+ # Update 'code' cell count
340
+ cell_num += 1
330
341
loc = '%s:Cell %d' % (getattr (self , "fspath" , None ), cell_num )
331
342
if set (comment_opts .keys ()) & set (options .keys ()):
332
343
warnings .warn_explicit (
@@ -345,8 +356,9 @@ def collect(self):
345
356
lineno = 0
346
357
)
347
358
options .update (comment_opts )
359
+ options .setdefault ('name' , 'Cell %d' % cell_num )
348
360
options .setdefault ('check' , self .compare_outputs )
349
- name = 'Cell ' + str ( cell_num )
361
+ name = options [ 'name' ]
350
362
# https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
351
363
if hasattr (IPyNbCell , "from_parent" ):
352
364
yield IPyNbCell .from_parent (
@@ -355,9 +367,6 @@ def collect(self):
355
367
else :
356
368
yield IPyNbCell (name , self , cell_num , cell , options )
357
369
358
- # Update 'code' cell count
359
- cell_num += 1
360
-
361
370
def teardown (self ):
362
371
if self .kernel is not None and self .kernel .is_alive ():
363
372
if getattr (self .parent .config .option , 'cov_source' , None ):
0 commit comments