-# Source the generated environment file if it's present
-if [ -f "${BT_TESTS_BUILDDIR}/utils/env.sh" ]; then
- # shellcheck disable=SC1091
- . "${BT_TESTS_BUILDDIR}/utils/env.sh"
-fi
+# Sources the generated environment file (`env.sh`) if it exists.
+_source_env_sh() {
+ local -r env_sh_path="$BT_TESTS_BUILDDIR/utils/env.sh"
+
+ if [ -f "${env_sh_path}" ]; then
+ # shellcheck disable=SC1090,SC1091
+ . "${env_sh_path}"
+ fi
+}
+
+_source_env_sh
+unset -f _source_env_sh