-# Set the environment and run python tests in the directory.
-#
-# $1 : The directory containing the python test scripts
-# $2 : The pattern to match python test script names (optional)
-run_python_bt2_test() {
- local test_dir="$1"
- local test_pattern="${2:-'*'}" # optional, if none default to "*"
+# Executes a command within an environment which can import the testing
+# Python modules (in `tests/utils/python`) and the `bt2` Python package.
+bt_run_in_py_env() {
+ local -x BABELTRACE_PLUGIN_PATH=$BT_TESTS_BABELTRACE_PLUGIN_PATH
+ local -x LIBBABELTRACE2_PLUGIN_PROVIDER_DIR=$BT_TESTS_PROVIDER_DIR
+ local -x BT_TESTS_DATADIR=$BT_TESTS_DATADIR
+ local -x BT_CTF_TRACES_PATH=$BT_CTF_TRACES_PATH
+ local -x BT_PLUGINS_PATH=$_bt_tests_plugins_path
+ local -x PYTHONPATH=$BT_TESTS_PYTHONPATH${PYTHONPATH:+:}${PYTHONPATH:-}
+ local -r main_lib_path=$BT_TESTS_BUILDDIR/../src/lib/.libs
+
+ # Set the library search path so that the Python 3 interpreter can
+ # load `libbabeltrace2`.
+ if [[ $BT_TESTS_OS_TYPE == mingw || $BT_TESTS_OS_TYPE == cygwin ]]; then
+ local -x PATH=$main_lib_path${PATH:+:}${PATH:-}
+ elif [[ $BT_TESTS_OS_TYPE == darwin ]]; then
+ local -x DYLD_LIBRARY_PATH=$main_lib_path${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH:-}
+ else
+ local -x LD_LIBRARY_PATH=$main_lib_path${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH:-}
+ fi
+
+ # On Windows, an embedded Python 3 interpreter needs a way to locate
+ # the path to its internal modules: set the `PYTHONHOME` variable to
+ # the prefix from `python3-config`.
+ if [[ $BT_TESTS_OS_TYPE == mingw ]]; then
+ local -x PYTHONHOME