From 0d987b0e4bc61eaf536c7bc2a8f2f839804ce442 Mon Sep 17 00:00:00 2001 From: rockandska Date: Mon, 8 Sep 2025 15:36:12 +0200 Subject: [PATCH] fix test isolation Make sur that PYENV_TEST_DIR is created if mktemp failed mock python3 usage by updating create_executable function fix test by adding the right PATH update path in plugin test replace for loop with while read don't use symlink for stub --- plugins/python-build/test/build.bats | 13 +++++++++ plugins/python-build/test/definitions.bats | 4 +-- plugins/python-build/test/test_helper.bash | 6 ++--- test/exec.bats | 31 +++++++++++++++------- test/prefix.bats | 4 +-- test/test_helper.bash | 1 + test/versions.bats | 1 + 7 files changed, 43 insertions(+), 17 deletions(-) diff --git a/plugins/python-build/test/build.bats b/plugins/python-build/test/build.bats index 01e48630..b0c02aa9 100644 --- a/plugins/python-build/test/build.bats +++ b/plugins/python-build/test/build.bats @@ -378,6 +378,9 @@ OUT stub port "-q installed libyaml : echo ' libyaml @0.2.5_0 (active)'" for i in {1..3}; do stub port false; done stub_make_install + export PYTHON_BUILD_SKIP_HOMEBREW=1 + PORT_PREFIX="$(which port)" + PORT_PREFIX="${PORT_PREFIX%/bin/port}" install_fixture definitions/needs-yaml assert_success @@ -403,6 +406,9 @@ OUT stub port "-q installed readline : echo ' readline @8.2.013_0 (active)'" for i in {1..2}; do stub port false; done stub_make_install + export PYTHON_BUILD_SKIP_HOMEBREW=1 + PORT_PREFIX="$(which port)" + PORT_PREFIX="${PORT_PREFIX%/bin/port}" run_inline_definition <> "${TMP}/${program}-stub-plan"; done diff --git a/test/exec.bats b/test/exec.bats index b643d31e..97218310 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -8,7 +8,7 @@ create_executable() { bin="${PYENV_ROOT}/versions/${PYENV_VERSION}/bin" mkdir -p "$bin" { if [ $# -eq 0 ]; then cat - - else echo "$@" + else printf '%s\n' "$@" fi } | sed -Ee '1s/^ +//' > "${bin}/$name" chmod +x "${bin}/$name" @@ -85,18 +85,25 @@ OUT } @test "sys.executable with system version (#98)" { - system_python="$(python3 -c 'import sys; print(sys.executable)')" + export PATH="${PYENV_ROOT}/versions/bin:${PATH}" + create_executable "python3" < "${PYENV_TEST_DIR}/python3" </dev/null || echo "$PYENV_TEST_DIR")" + mkdir -p "${PYENV_TEST_DIR}" if enable -f "${BATS_TEST_DIRNAME}"/../libexec/pyenv-realpath.dylib realpath 2>/dev/null; then export PYENV_TEST_DIR="$(realpath "$PYENV_TEST_DIR")" diff --git a/test/versions.bats b/test/versions.bats index ad2cf07a..ef03dfad 100644 --- a/test/versions.bats +++ b/test/versions.bats @@ -238,6 +238,7 @@ OUT } @test "non-bare output shows symlink contents" { + stub_system_python create_version "1.9.0" create_alias "link" "1.9.0"