From 76e052aa9094708e24783641aa0f3c30df791535 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 4 Mar 2024 10:11:58 +0000 Subject: [PATCH] Switch collection hook to use pathlib paths --- nbval/plugin.py | 13 +++---------- setup.py | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/nbval/plugin.py b/nbval/plugin.py index 7e75a5d..aee551f 100644 --- a/nbval/plugin.py +++ b/nbval/plugin.py @@ -134,21 +134,14 @@ def pytest_configure(config): -def pytest_collect_file(path, parent): +def pytest_collect_file(collection_path, parent): """ Collect IPython notebooks using the specified pytest hook """ opt = parent.config.option - if (opt.nbval or opt.nbval_lax) and path.fnmatch("*.ipynb"): + if (opt.nbval or opt.nbval_lax) and collection_path.suffix == ".ipynb": # https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent - if hasattr(IPyNbFile, "from_parent"): - try: # Pytest >= 7.0.0 - return IPyNbFile.from_parent(parent, path=Path(path)) - except AssertionError: - return IPyNbFile.from_parent(parent, fspath=path) - else: # Pytest < 5.4 - return IPyNbFile(path, parent) - + return IPyNbFile.from_parent(parent, path=collection_path) comment_markers = { diff --git a/setup.py b/setup.py index 3448f98..f20eb7b 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ ] }, install_requires = [ - 'pytest >= 2.8', + 'pytest >= 7', 'jupyter_client', 'nbformat', 'ipykernel',