Skip to content

Commit

Permalink
Use lru_cache clear fixture at test module level
Browse files Browse the repository at this point in the history
  • Loading branch information
akaihola committed Jan 30, 2023
1 parent 41924fe commit f8f36ee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/darker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ def git_repo(tmp_path, monkeypatch):
def find_project_root_cache_clear():
"""Clear LRU caching in :func:`black.find_project_root` before each test
To use this on all test cases in a test module, add this to the top::
pytestmark = pytest.mark.usefixtures("find_project_root_cache_clear")
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.
Expand Down
4 changes: 3 additions & 1 deletion src/darker/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
)
from darker.tests.helpers import raises_if_exception

pytestmark = pytest.mark.usefixtures("find_project_root_cache_clear")


@pytest.mark.kwparametrize(
dict(list_value=[], expect="[\n]"),
Expand Down Expand Up @@ -376,7 +378,7 @@ def test_output_mode_from_args(diff, stdout, expect):
expect={"CONFIG_PATH": "."},
)
def test_load_config( # pylint: disable=too-many-arguments
find_project_root_cache_clear, tmp_path, monkeypatch, srcs, cwd, confpath, expect
tmp_path, monkeypatch, srcs, cwd, confpath, expect
):
"""``load_config()`` finds and loads configuration based on source file paths"""
(tmp_path / ".git").mkdir()
Expand Down
11 changes: 3 additions & 8 deletions src/darker/tests/test_import_sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
ORIGINAL_SOURCE = ("import sys", "import os", "", "print(42)")
ISORTED_SOURCE = ("import os", "import sys", "", "print(42)")

pytestmark = pytest.mark.usefixtures("find_project_root_cache_clear")


@pytest.mark.parametrize("present", [True, False])
def test_import_sorting_importable_with_and_without_isort(present):
Expand Down Expand Up @@ -132,14 +134,7 @@ def test_apply_isort_exclude(git_repo, encoding, newline, content, exclude, expe
),
),
)
def test_isort_config(
monkeypatch,
tmpdir,
find_project_root_cache_clear,
line_length,
settings_file,
expect,
):
def test_isort_config(monkeypatch, tmpdir, line_length, settings_file, expect):
"""``apply_isort()`` parses ``pyproject.toml``correctly"""
monkeypatch.chdir(tmpdir)
(tmpdir / "pyproject.toml").write(
Expand Down
9 changes: 4 additions & 5 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
from darker.utils import TextDocument, joinlines
from darker.verification import NotEquivalentError

pytestmark = pytest.mark.usefixtures("find_project_root_cache_clear")


def _replace_diff_timestamps(text, replacement="<timestamp>"):
return re.sub(r"\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d\d\d\d", replacement, text)
Expand All @@ -45,7 +47,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):
"""Fixture for running Darker with requested arguments and a patched `isort`
Provides an `run_isort.isort_code` mock object which allows checking whether and how
Expand Down Expand Up @@ -470,7 +472,6 @@ def test_main(
git_repo,
monkeypatch,
capsys,
find_project_root_cache_clear,
arguments,
newline,
pyproject_toml,
Expand Down Expand Up @@ -573,9 +574,7 @@ def test_main_in_plain_directory(tmp_path, capsys):
"encoding, text", [(b"utf-8", b"touch\xc3\xa9"), (b"iso-8859-1", b"touch\xe9")]
)
@pytest.mark.parametrize("newline", [b"\n", b"\r\n"])
def test_main_encoding(
git_repo, find_project_root_cache_clear, encoding, text, newline
):
def test_main_encoding(git_repo, encoding, text, newline):
"""Encoding and newline of the file is kept unchanged after reformatting"""
paths = git_repo.add({"a.py": newline.decode("ascii")}, commit="Initial commit")
edited = [b"# coding: ", encoding, newline, b's="', text, b'"', newline]
Expand Down

0 comments on commit f8f36ee

Please sign in to comment.