summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiro HronĨok <miro@hroncok.cz>2021-12-03 19:43:14 +0100
committerGitHub <noreply@github.com>2021-12-03 18:43:14 +0000
commitd3fee0ebb72a514fac66cd3101a67cd31d741254 (patch)
treeb933faa39cb2199b2636bcc17c559785d6f7c95a
parent623189a00aa96c805990fd12dc883c69e251f4b2 (diff)
downloadvirtualenv-d3fee0ebb72a514fac66cd3101a67cd31d741254.tar.gz
Fix test_custom_venv_install_scheme_is_prefered mocking if "venv" install scheme actually exists (#2231)
-rw-r--r--tests/unit/discovery/py_info/test_py_info.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/tests/unit/discovery/py_info/test_py_info.py b/tests/unit/discovery/py_info/test_py_info.py
index 053a6f9..d4c4bba 100644
--- a/tests/unit/discovery/py_info/test_py_info.py
+++ b/tests/unit/discovery/py_info/test_py_info.py
@@ -349,7 +349,6 @@ def test_custom_venv_install_scheme_is_prefered(mocker):
if sys.version_info[0] == 2:
sysconfig_install_schemes = _stringify_schemes_dict(sysconfig_install_schemes)
- mocker.patch("sysconfig._INSTALL_SCHEMES", sysconfig_install_schemes)
# On Python < 3.10, the distutils schemes are not derived from sysconfig schemes
# So we mock them as well to assert the custom "venv" install scheme has priority
@@ -367,7 +366,15 @@ def test_custom_venv_install_scheme_is_prefered(mocker):
if sys.version_info[0] == 2:
distutils_schemes = _stringify_schemes_dict(distutils_schemes)
+
+ # We need to mock distutils first, so they don't see the mocked sysconfig,
+ # if imported for the first time.
+ # That can happen if the actual interpreter has the "venv" INSTALL_SCHEME
+ # and hence this is the first time we are touching distutils in this process.
+ # If distutils saw our mocked sysconfig INSTALL_SCHEMES, we would need
+ # to define all install schemes.
mocker.patch("distutils.command.install.INSTALL_SCHEMES", distutils_schemes)
+ mocker.patch("sysconfig._INSTALL_SCHEMES", sysconfig_install_schemes)
pyinfo = PythonInfo()
pyver = "{}.{}".format(pyinfo.version_info.major, pyinfo.version_info.minor)