@@ -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 (
@@ -147,6 +147,7 @@ def pytest_collect_file(file_path, parent):
147
147
comment_markers = {
148
148
'PYTEST_VALIDATE_IGNORE_OUTPUT' : ('check' , False ), # For backwards compatibility
149
149
'NBVAL_IGNORE_OUTPUT' : ('check' , False ),
150
+ 'NBVAL_TEST_NAME' : ('name' , str ),
150
151
'NBVAL_CHECK_OUTPUT' : 'check' ,
151
152
'NBVAL_RAISES_EXCEPTION' : 'check_exception' ,
152
153
'NBVAL_SKIP' : 'skip' ,
@@ -170,14 +171,22 @@ def find_comment_markers(cellsource):
170
171
line = line .strip ()
171
172
if line .startswith ('#' ):
172
173
# print("Found comment in '{}'".format(line))
173
- comment = line .lstrip ('#' ).strip ()
174
+ comment_val = line .lstrip ('#' ).strip ()
175
+ if ':' in comment_val :
176
+ comment , val = comment_val .split (':' , 1 )
177
+ comment = comment .rstrip ()
178
+ val = val .lstrip ()
179
+ else :
180
+ comment = comment_val
174
181
if comment in comment_markers :
175
182
# print("Found marker {}".format(comment))
176
183
marker = comment_markers [comment ]
177
184
if not isinstance (marker , tuple ):
178
185
# If not an explicit tuple ('option', True/False),
179
186
# imply ('option', True)
180
187
marker = (marker , True )
188
+ elif marker [1 ] is str :
189
+ marker = (marker [0 ], val )
181
190
marker_type = marker [0 ]
182
191
if marker_type in found :
183
192
warnings .warn (
@@ -264,7 +273,7 @@ def setup(self):
264
273
self .kernel = RunningKernel (
265
274
kernel_name ,
266
275
cwd = str (self .fspath .dirname ),
267
- startup_timeout = self .config .option .nbval_kernel_startup_timeout ,
276
+ startup_timeout = self .config .option .nbval_kernel_startup_timeout ,
268
277
)
269
278
self .setup_sanitize_files ()
270
279
if getattr (self .parent .config .option , 'cov_source' , None ):
@@ -324,6 +333,8 @@ def collect(self):
324
333
with warnings .catch_warnings (record = True ) as ws :
325
334
options = defaultdict (bool , find_metadata_tags (cell .metadata ))
326
335
comment_opts = dict (find_comment_markers (cell .source ))
336
+ # Update 'code' cell count
337
+ cell_num += 1
327
338
loc = '%s:Cell %d' % (getattr (self , "fspath" , None ), cell_num )
328
339
if set (comment_opts .keys ()) & set (options .keys ()):
329
340
warnings .warn_explicit (
@@ -342,15 +353,13 @@ def collect(self):
342
353
lineno = 0
343
354
)
344
355
options .update (comment_opts )
356
+ options .setdefault ('name' , f'Cell { cell_num :d} ' )
345
357
options .setdefault ('check' , self .compare_outputs )
346
- name = 'Cell ' + str ( cell_num )
358
+ name = options [ 'name' ]
347
359
yield IPyNbCell .from_parent (
348
360
self , name = name , cell_num = cell_num , cell = cell , options = options
349
361
)
350
362
351
- # Update 'code' cell count
352
- cell_num += 1
353
-
354
363
def teardown (self ):
355
364
if self .kernel is not None and self .kernel .is_alive ():
356
365
if getattr (self .parent .config .option , 'cov_source' , None ):
0 commit comments