diff --git a/cpp/src/arrow/filesystem/gcsfs_test.cc b/cpp/src/arrow/filesystem/gcsfs_test.cc index 3024d329f70f..4f88aaced615 100644 --- a/cpp/src/arrow/filesystem/gcsfs_test.cc +++ b/cpp/src/arrow/filesystem/gcsfs_test.cc @@ -78,11 +78,32 @@ class GcsIntegrationTest : public ::testing::Test { // Initialize a PRNG with a small amount of entropy. generator_ = std::mt19937_64(std::random_device()()); port_ = std::to_string(GetListenPort()); - auto exe_path = bp::search_path("python3"); - ASSERT_THAT(exe_path, Not(IsEmpty())); - - server_process_ = bp::child(boost::this_process::environment(), exe_path, "-m", - "testbench", "--port", port_, group_); + std::vector names{"python3", "python"}; + // If the build script or application developer provides a value in the PYTHON + // environment variable, then just use that. + if (const auto* env = std::getenv("PYTHON")) { + names = {env}; + } + auto error = std::string( + "Cloud not start GCS emulator." + " Used the following list of python interpreter names:"); + for (const auto& interpreter : names) { + auto exe_path = bp::search_path(interpreter); + error += " " + interpreter; + if (exe_path.empty()) { + error += " (exe not found)"; + continue; + } + + server_process_ = bp::child(boost::this_process::environment(), exe_path, "-m", + "testbench", "--port", port_, group_); + if (server_process_.valid() && server_process_.running()) break; + error += " (failed to start)"; + server_process_.terminate(); + server_process_.wait(); + } + ASSERT_TRUE(server_process_.valid()) << error; + ASSERT_TRUE(server_process_.running()) << error; // Create a bucket and a small file in the testbench. This makes it easier to // bootstrap GcsFileSystem and its tests.