Skip to content

Commit ba195c5

Browse files
committed
Replace deprecated warning API
The warnings capture also caused an infinite loop of generating and emitting warnings.
1 parent 170ed02 commit ba195c5

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

nbval/cover.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77
import coverage
8+
import warnings
89

910

1011
# Coverage setup/teardown code to run in kernel
@@ -66,10 +67,12 @@ def setup_coverage(config, kernel, floc, output_loc=None):
6667
msg_id = kernel.kc.execute(cmd, stop_on_error=False)
6768
kernel.await_idle(msg_id, 60) # A minute should be plenty to enable coverage
6869
else:
69-
config.warn(
70-
'C1',
70+
warnings.warn_explicit(
7171
'Coverage currently not supported for language "%s".' % language,
72-
floc)
72+
category=UserWarning,
73+
filename=floc[0] if floc else '',
74+
lineno=0
75+
)
7376
return
7477

7578

nbval/plugin.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,23 @@ def collect(self):
288288
with warnings.catch_warnings(record=True) as ws:
289289
options = defaultdict(bool, find_metadata_tags(cell.metadata))
290290
comment_opts = dict(find_comment_markers(cell.source))
291-
if set(comment_opts.keys()) & set(options.keys()):
292-
warnings.warn(
293-
"Overlapping options from comments and metadata, "
294-
"using options from comments: %s" %
295-
str(set(comment_opts.keys()) & set(options.keys())))
296-
for w in ws:
297-
self.parent.config.warn(
298-
"C1",
299-
str(w.message),
300-
'%s:Cell %d' % (
301-
getattr(self, "fspath", None),
302-
cell_num))
291+
loc = '%s:Cell %d' % (getattr(self, "fspath", None), cell_num)
292+
if set(comment_opts.keys()) & set(options.keys()):
293+
warnings.warn_explicit(
294+
"Overlapping options from comments and metadata, "
295+
"using options from comments: %s" %
296+
str(set(comment_opts.keys()) & set(options.keys())),
297+
category=UserWarning,
298+
filename=loc,
299+
lineno=0
300+
)
301+
for w in ws:
302+
warnings.warn_explicit(
303+
str(w.message),
304+
category=UserWarning,
305+
filename=loc,
306+
lineno=0
307+
)
303308
options.update(comment_opts)
304309
options.setdefault('check', self.compare_outputs)
305310
yield IPyNbCell('Cell ' + str(cell_num), self, cell_num,

0 commit comments

Comments
 (0)