From 338d03ac2218455374b4e35f495c6574712b3681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Tue, 3 Nov 2020 12:45:13 +0100 Subject: [PATCH] In tests, get sys.exec_prefix from the resolved executable The previous version (resolving the exec_prefix) no longer works for me. Also, apparently my current environment is different in tests (it is the "absolutely current" now), so I've adapted test_noquiet_installed_packages. Not very sure about what has changed, but this has been always fragile. --- tests/test_integration.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tests/test_integration.py b/tests/test_integration.py index 5428d70..86b7e53 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -15,12 +15,20 @@ import pytest NATIVE_TOXENV = f"py{sys.version_info[0]}{sys.version_info[1]}" NATIVE_EXECUTABLE = str(pathlib.Path(sys.executable).resolve()) -NATIVE_EXEC_PREFIX = str(pathlib.Path(sys.exec_prefix).resolve()) -NATIVE_EXEC_PREFIX_MSG = f"{NATIVE_EXEC_PREFIX} is the exec_prefix" FIXTURES_DIR = pathlib.Path(__file__).parent / "fixtures" DOT_TOX = pathlib.Path("./.tox") +def _exec_prefix(executable): + """Returns sys.exec_prefix for the given executable""" + cmd = (executable, "-c", "import sys; print(sys.exec_prefix)") + return subprocess.check_output(cmd, encoding="utf-8").strip() + + +NATIVE_EXEC_PREFIX = _exec_prefix(NATIVE_EXECUTABLE) +NATIVE_EXEC_PREFIX_MSG = f"{NATIVE_EXEC_PREFIX} is the exec_prefix" + + @pytest.fixture(autouse=True) def projdir(tmp_path, monkeypatch): pwd = tmp_path / "projdir" @@ -524,7 +532,7 @@ def test_noquiet_installed_packages(flag): # default tox produces output sorted by package names assert packages == sorted( - packages, key=lambda p: p.partition("==")[0].partition(" @ ")[0] + packages, key=lambda p: p.partition("==")[0].partition(" @ ")[0].lower() ) # without a flag, the output must match tox defaults @@ -534,8 +542,7 @@ def test_noquiet_installed_packages(flag): assert packages[1].startswith("six==") assert packages[2].startswith(("test==", "test @ ")) # old and new pip - # with our flags, uses the current environment by default, hence has tox, pytest + # with our flags, uses the absolutely current environment by default, hence has tox else: - assert f"tox=={TOX_VERSION}" in packages - assert len([p for p in packages if p.startswith("pytest==")]) == 1 + assert len([p for p in packages if p.startswith("tox==")]) == 1 assert all(re.match(r"\S+==\S+", p) for p in packages)