Skip to content

Commit

Permalink
Switch collection hook to use pathlib paths
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Mar 4, 2024
1 parent d7bc348 commit 76e052a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions nbval/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
]
},
install_requires = [
'pytest >= 2.8',
'pytest >= 7',
'jupyter_client',
'nbformat',
'ipykernel',
Expand Down

0 comments on commit 76e052a

Please sign in to comment.