diff --git a/nbval/plugin.py b/nbval/plugin.py index 34dcce5..1566da5 100644 --- a/nbval/plugin.py +++ b/nbval/plugin.py @@ -16,6 +16,7 @@ import warnings from collections import OrderedDict, defaultdict +from pathlib import Path from queue import Empty # for reading notebook files @@ -141,7 +142,10 @@ def pytest_collect_file(path, parent): if (opt.nbval or opt.nbval_lax) and path.fnmatch("*.ipynb"): # https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent if hasattr(IPyNbFile, "from_parent"): - return IPyNbFile.from_parent(parent, fspath=path) + try: + return IPyNbFile.from_parent(parent, path=Path(path)) + except Exception: # Pytest < 7.0 + return IPyNbFile.from_parent(parent, fspath=path) else: # Pytest < 5.4 return IPyNbFile(path, parent)