Skip to content

Commit 7c6cd71

Browse files
authored
Merge pull request #110 from vidartf/fix-tests
Fix warnings + test
2 parents 170ed02 + fb17750 commit 7c6cd71

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

nbval/cover.py

Lines changed: 7 additions & 4 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',
71-
'Coverage currently not supported for language "%s".' % language,
72-
floc)
70+
warnings.warn_explicit(
71+
'Coverage currently not supported for language %r.' % language,
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,

tests/test_coverage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pytest_plugins = "pytester"
99

1010

11-
_re_coverage_report_line = re.compile('^(\w)\s*(\d+)\s*(\d+)\s*(\d+)%$')
11+
_re_coverage_report_line = re.compile(r'^(\w)\s*(\d+)\s*(\d+)\s*(\d+)%$')
1212

1313

1414
def test_coverage(testdir):
@@ -49,7 +49,7 @@ def test_sum():
4949
result = testdir.runpytest_inprocess('--nbval', '--current-env', '--cov', '.')
5050

5151
# Check tests went off as they should:
52-
result.ret == 0
52+
assert result.ret == 0
5353

5454
# Ensure coverage report was generated:
5555
assert os.path.exists(os.path.join(str(testdir.tmpdir), '.coverage'))

0 commit comments

Comments
 (0)