mirror of
https://github.com/fedora-python/tox-current-env.git
synced 2025-01-25 22:36:14 +01:00
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.
This commit is contained in:
parent
b35f8832a9
commit
338d03ac22
@ -15,12 +15,20 @@ import pytest
|
|||||||
|
|
||||||
NATIVE_TOXENV = f"py{sys.version_info[0]}{sys.version_info[1]}"
|
NATIVE_TOXENV = f"py{sys.version_info[0]}{sys.version_info[1]}"
|
||||||
NATIVE_EXECUTABLE = str(pathlib.Path(sys.executable).resolve())
|
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"
|
FIXTURES_DIR = pathlib.Path(__file__).parent / "fixtures"
|
||||||
DOT_TOX = pathlib.Path("./.tox")
|
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)
|
@pytest.fixture(autouse=True)
|
||||||
def projdir(tmp_path, monkeypatch):
|
def projdir(tmp_path, monkeypatch):
|
||||||
pwd = tmp_path / "projdir"
|
pwd = tmp_path / "projdir"
|
||||||
@ -524,7 +532,7 @@ def test_noquiet_installed_packages(flag):
|
|||||||
|
|
||||||
# default tox produces output sorted by package names
|
# default tox produces output sorted by package names
|
||||||
assert packages == sorted(
|
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
|
# 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[1].startswith("six==")
|
||||||
assert packages[2].startswith(("test==", "test @ ")) # old and new pip
|
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:
|
else:
|
||||||
assert f"tox=={TOX_VERSION}" in packages
|
assert len([p for p in packages if p.startswith("tox==")]) == 1
|
||||||
assert len([p for p in packages if p.startswith("pytest==")]) == 1
|
|
||||||
assert all(re.match(r"\S+==\S+", p) for p in packages)
|
assert all(re.match(r"\S+==\S+", p) for p in packages)
|
||||||
|
Loading…
Reference in New Issue
Block a user