|
2 | 2 | import os
|
3 | 3 | import re
|
4 | 4 | from contextlib import ExitStack
|
| 5 | +from pathlib import Path |
5 | 6 | from unittest.mock import patch
|
6 | 7 |
|
7 | 8 | import pytest
|
|
27 | 28 | @pytest.fixture(autouse=True, scope="session")
|
28 | 29 | def setup_package():
|
29 | 30 | import tempfile
|
30 |
| - from pathlib import Path |
31 | 31 |
|
32 | 32 | from datalad import consts
|
33 | 33 | from datalad.support.annexrepo import AnnexRepo
|
@@ -238,25 +238,23 @@ def capture_logs(caplog, monkeypatch):
|
238 | 238 | monkeypatch.setenv('DATALAD_LOG_LEVEL', '100')
|
239 | 239 |
|
240 | 240 |
|
241 |
| -def pytest_ignore_collect(path): |
| 241 | +def pytest_ignore_collect(collection_path: Path) -> bool: |
242 | 242 | # Skip old nose code and the tests for it:
|
243 | 243 | # Note, that this is not only about executing tests but also importing those
|
244 | 244 | # files to begin with.
|
245 |
| - if path.basename == "test_tests_utils.py": |
| 245 | + if collection_path.name == "test_tests_utils.py": |
246 | 246 | 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"): |
250 | 248 | return True
|
251 | 249 | # When pytest is told to run doctests, by default it will import every
|
252 | 250 | # source file in its search, but a number of datalad source file have
|
253 | 251 | # undesirable side effects when imported. This hook should ensure that
|
254 | 252 | # only `test_*.py` files and `*.py` files containing doctests are imported
|
255 | 253 | # 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(): |
257 | 255 | return False
|
258 |
| - if path.ext != ".py": |
| 256 | + if collection_path.suffix != ".py": |
259 | 257 | return True
|
260 | 258 | 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() |
262 | 260 | )
|
0 commit comments