Skip to content

Commit 08315c1

Browse files
authored
Merge pull request datalad#7546 from jwodder/pytest-path-hook
Update `pytest_ignore_collect()` for pytest 8.0
2 parents 492a4f7 + 7f6cadb commit 08315c1

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

changelog.d/pr-7546.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### 🏠 Internal
2+
3+
- Update `pytest_ignore_collect()` for pytest 8.0. [PR #7546](https://github.com/datalad/datalad/pull/7546) (by [@jwodder](https://github.com/jwodder))

datalad/conftest.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import re
44
from contextlib import ExitStack
5+
from pathlib import Path
56
from unittest.mock import patch
67

78
import pytest
@@ -27,7 +28,6 @@
2728
@pytest.fixture(autouse=True, scope="session")
2829
def setup_package():
2930
import tempfile
30-
from pathlib import Path
3131

3232
from datalad import consts
3333
from datalad.support.annexrepo import AnnexRepo
@@ -238,25 +238,23 @@ def capture_logs(caplog, monkeypatch):
238238
monkeypatch.setenv('DATALAD_LOG_LEVEL', '100')
239239

240240

241-
def pytest_ignore_collect(path):
241+
def pytest_ignore_collect(collection_path: Path) -> bool:
242242
# Skip old nose code and the tests for it:
243243
# Note, that this is not only about executing tests but also importing those
244244
# files to begin with.
245-
if path.basename == "test_tests_utils.py":
245+
if collection_path.name == "test_tests_utils.py":
246246
return True
247-
if path.basename == "utils.py" and \
248-
path.dirpath().basename == "tests" and \
249-
path.dirpath().dirpath().basename == "datalad":
247+
if collection_path.parts[:-3] == ("datalad", "tests", "utils.py"):
250248
return True
251249
# When pytest is told to run doctests, by default it will import every
252250
# source file in its search, but a number of datalad source file have
253251
# undesirable side effects when imported. This hook should ensure that
254252
# only `test_*.py` files and `*.py` files containing doctests are imported
255253
# during test collection.
256-
if path.basename.startswith("test_") or path.check(dir=1):
254+
if collection_path.name.startswith("test_") or collection_path.is_dir():
257255
return False
258-
if path.ext != ".py":
256+
if collection_path.suffix != ".py":
259257
return True
260258
return not any(
261-
re.match(r"^\s*>>>", ln) for ln in path.read_text("utf-8").splitlines()
259+
re.match(r"^\s*>>>", ln) for ln in collection_path.read_text("utf-8").splitlines()
262260
)

0 commit comments

Comments
 (0)