diff --git a/src/darker/black_compat.py b/src/darker/black_compat.py index b5c8e2749..81ad542c2 100644 --- a/src/darker/black_compat.py +++ b/src/darker/black_compat.py @@ -19,6 +19,3 @@ def find_project_root(srcs: Sequence[str]) -> Path: return cast(Tuple[Path], root)[0] # Black < 22 return cast(Path, root) - - -find_project_root.cache_clear = black_find_project_root.cache_clear diff --git a/src/darker/tests/conftest.py b/src/darker/tests/conftest.py index 10e72b157..a2b844ac1 100644 --- a/src/darker/tests/conftest.py +++ b/src/darker/tests/conftest.py @@ -6,8 +6,8 @@ from typing import Dict, Optional import pytest +from black import find_project_root as black_find_project_root -from darker.black_compat import find_project_root from darker.git import _git_check_output_lines @@ -97,5 +97,11 @@ def git_repo(tmp_path, monkeypatch): @pytest.fixture def find_project_root_cache_clear(): - """Clear LRU caching in :func:`black.find_project_root` before each test""" - find_project_root.cache_clear() + """Clear LRU caching in :func:`black.find_project_root` before each test + + NOTE: We use `darker.black_compat.find_project_root` to wrap Black's original + function since its signature has changed along the way. However, clearing the cache + needs to be done on the original of course. + + """ + black_find_project_root.cache_clear() diff --git a/src/darker/tests/test_import_sorting.py b/src/darker/tests/test_import_sorting.py index ecb676748..266574a5f 100644 --- a/src/darker/tests/test_import_sorting.py +++ b/src/darker/tests/test_import_sorting.py @@ -7,7 +7,6 @@ import pytest import darker.import_sorting -from darker.black_compat import find_project_root from darker.tests.helpers import isort_present from darker.utils import TextDocument @@ -76,9 +75,15 @@ def test_apply_isort(encoding, newline): ), ), ) -def test_isort_config(monkeypatch, tmpdir, line_length, settings_file, expect): +def test_isort_config( + monkeypatch, + tmpdir, + find_project_root_cache_clear, + line_length, + settings_file, + expect, +): """``apply_isort()`` parses ``pyproject.toml``correctly""" - find_project_root.cache_clear() monkeypatch.chdir(tmpdir) (tmpdir / "pyproject.toml").write( dedent( diff --git a/src/darker/tests/test_main.py b/src/darker/tests/test_main.py index 1277c5222..e385ac25d 100644 --- a/src/darker/tests/test_main.py +++ b/src/darker/tests/test_main.py @@ -15,7 +15,6 @@ import darker.__main__ import darker.import_sorting import darker.linting -from darker.black_compat import find_project_root from darker.exceptions import MissingPackageError from darker.git import WORKTREE, RevisionRange from darker.tests.helpers import isort_present @@ -38,9 +37,7 @@ def test_isort_option_without_isort(git_repo, caplog): @pytest.fixture -def run_isort(git_repo, monkeypatch, caplog, request): - find_project_root.cache_clear() - +def run_isort(git_repo, monkeypatch, caplog, request, find_project_root_cache_clear): monkeypatch.chdir(git_repo.root) paths = git_repo.add({"test1.py": "original"}, commit="Initial commit") paths["test1.py"].write_bytes(b"changed")