@@ -105,7 +105,7 @@ def pytest_addoption(parser):
105105 help = '(deprecated) Alias of --nbval-sanitize-with' )
106106
107107 group .addoption ('--current-env' , action = 'store_true' ,
108- help = '(deprecated) Alias of --nbval-current-env' )
108+ help = '(deprecated) Alias of --nbval-current-env' )
109109
110110 term_group = parser .getgroup ("terminal reporting" )
111111 term_group ._addoption (
@@ -154,6 +154,7 @@ def pytest_collect_file(path, parent):
154154comment_markers = {
155155 'PYTEST_VALIDATE_IGNORE_OUTPUT' : ('check' , False ), # For backwards compatibility
156156 'NBVAL_IGNORE_OUTPUT' : ('check' , False ),
157+ 'NBVAL_TEST_NAME' : ('name' , str ),
157158 'NBVAL_CHECK_OUTPUT' : 'check' ,
158159 'NBVAL_RAISES_EXCEPTION' : 'check_exception' ,
159160 'NBVAL_SKIP' : 'skip' ,
@@ -177,14 +178,22 @@ def find_comment_markers(cellsource):
177178 line = line .strip ()
178179 if line .startswith ('#' ):
179180 # 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
181188 if comment in comment_markers :
182189 # print("Found marker {}".format(comment))
183190 marker = comment_markers [comment ]
184191 if not isinstance (marker , tuple ):
185192 # If not an explicit tuple ('option', True/False),
186193 # imply ('option', True)
187194 marker = (marker , True )
195+ elif marker [1 ] is str :
196+ marker = (marker [0 ], val )
188197 marker_type = marker [0 ]
189198 if marker_type in found :
190199 warnings .warn (
@@ -271,7 +280,7 @@ def setup(self):
271280 self .kernel = RunningKernel (
272281 kernel_name ,
273282 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 ,
275284 )
276285 self .setup_sanitize_files ()
277286 if getattr (self .parent .config .option , 'cov_source' , None ):
@@ -331,6 +340,8 @@ def collect(self):
331340 with warnings .catch_warnings (record = True ) as ws :
332341 options = defaultdict (bool , find_metadata_tags (cell .metadata ))
333342 comment_opts = dict (find_comment_markers (cell .source ))
343+ # Update 'code' cell count
344+ cell_num += 1
334345 loc = '%s:Cell %d' % (getattr (self , "fspath" , None ), cell_num )
335346 if set (comment_opts .keys ()) & set (options .keys ()):
336347 warnings .warn_explicit (
@@ -349,8 +360,9 @@ def collect(self):
349360 lineno = 0
350361 )
351362 options .update (comment_opts )
363+ options .setdefault ('name' , 'Cell %d' % cell_num )
352364 options .setdefault ('check' , self .compare_outputs )
353- name = 'Cell ' + str ( cell_num )
365+ name = options [ 'name' ]
354366 # https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
355367 if hasattr (IPyNbCell , "from_parent" ):
356368 yield IPyNbCell .from_parent (
@@ -359,9 +371,6 @@ def collect(self):
359371 else :
360372 yield IPyNbCell (name , self , cell_num , cell , options )
361373
362- # Update 'code' cell count
363- cell_num += 1
364-
365374 def teardown (self ):
366375 if self .kernel is not None and self .kernel .is_alive ():
367376 if getattr (self .parent .config .option , 'cov_source' , None ):
0 commit comments