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