Skip to content

Commit f2ce5e7

Browse files
committed
Use new Node.from_parent constructor when available
Fixes compatibility with pytest >=6. Closes computationalmodellinggh-139
1 parent 3597e0b commit f2ce5e7

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

nbval/plugin.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def pytest_collect_file(path, parent):
112112
"""
113113
opt = parent.config.option
114114
if (opt.nbval or opt.nbval_lax) and path.fnmatch("*.ipynb"):
115-
return IPyNbFile(path, parent)
115+
# https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
116+
if hasattr(IPyNbFile, "from_parent"):
117+
return IPyNbFile.from_parent(parent, fspath=path)
118+
else: # Pytest < 5.4
119+
return IPyNbFile(path, parent)
116120

117121

118122

@@ -308,8 +312,14 @@ def collect(self):
308312
)
309313
options.update(comment_opts)
310314
options.setdefault('check', self.compare_outputs)
311-
yield IPyNbCell('Cell ' + str(cell_num), self, cell_num,
312-
cell, options)
315+
name = 'Cell ' + str(cell_num)
316+
# https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent
317+
if hasattr(IPyNbCell, "from_parent"):
318+
yield IPyNbCell.from_parent(
319+
self, name=name, cell_num=cell_num, cell=cell, options=options
320+
)
321+
else:
322+
yield IPyNbCell(name, self, cell_num, cell, options)
313323

314324
# Update 'code' cell count
315325
cell_num += 1

0 commit comments

Comments
 (0)