Skip to content

Commit d5f75e7

Browse files
committed
♻️ refactor(tests): stop importing private modules directly
Use from-imports and mocker.patch string paths instead of importing private modules as objects for monkeypatching.
1 parent 3b381df commit d5f75e7

2 files changed

Lines changed: 6 additions & 7 deletions

File tree

tests/test_py_info_extra.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import pytest
1111

12-
import py_discovery._compat
1312
from py_discovery import DiskCache, PythonInfo, PythonSpec
1413
from py_discovery._py_info import VersionInfo
1514

@@ -465,23 +464,23 @@ def test_possible_base_python_basename(mocker) -> None:
465464
assert "cpython" in names
466465

467466

468-
def test_possible_base_case_sensitive(monkeypatch: pytest.MonkeyPatch) -> None:
467+
def test_possible_base_case_sensitive(mocker) -> None:
469468
info = copy.deepcopy(CURRENT)
470469
info.executable = "/usr/bin/CPython3.12"
471470
info.implementation = "CPython"
472-
monkeypatch.setattr(py_discovery._compat, "fs_is_case_sensitive", lambda: True)
471+
mocker.patch("py_discovery._compat.fs_is_case_sensitive", return_value=True)
473472
names = list(info._possible_base())
474473
lower_names = [n for n in names if n.islower()]
475474
upper_names = [n for n in names if n.isupper()]
476475
assert len(lower_names) >= 1
477476
assert len(upper_names) >= 1
478477

479478

480-
def test_possible_base_case_sensitive_upper_equals_base(monkeypatch: pytest.MonkeyPatch) -> None:
479+
def test_possible_base_case_sensitive_upper_equals_base(mocker) -> None:
481480
info = copy.deepcopy(CURRENT)
482481
info.executable = "/usr/bin/JYTHON"
483482
info.implementation = "JYTHON"
484-
monkeypatch.setattr(py_discovery._compat, "fs_is_case_sensitive", lambda: True)
483+
mocker.patch("py_discovery._compat.fs_is_case_sensitive", return_value=True)
485484
names = list(info._possible_base())
486485
assert "jython" in names
487486
assert "JYTHON" in names

tests/windows/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def satisfies(spec, impl_must_match=False):
126126

127127
@pytest.fixture
128128
def _populate_pyinfo_cache(monkeypatch: pytest.MonkeyPatch) -> None:
129-
import py_discovery._cached_py_info
129+
from py_discovery._cached_py_info import _CACHE
130130

131131
python_core_path = "C:\\Users\\user\\AppData\\Local\\Programs\\Python"
132132
interpreters = [
@@ -145,4 +145,4 @@ def _populate_pyinfo_cache(monkeypatch: pytest.MonkeyPatch) -> None:
145145
]
146146
for _, major, minor, arch, threaded, exe in interpreters:
147147
info = _mock_pyinfo(major, minor, arch, exe, threaded)
148-
monkeypatch.setitem(py_discovery._cached_py_info._CACHE, Path(info.executable), info)
148+
monkeypatch.setitem(_CACHE, Path(info.executable), info)

0 commit comments

Comments
 (0)