Make toolchain acceptance tests work with latest Bazel build CI pipeline (#1062)

diff --git a/python/tests/toolchains/run_acceptance_test.py.tmpl b/python/tests/toolchains/run_acceptance_test.py.tmpl
index b3071a7..150e1a9 100644
--- a/python/tests/toolchains/run_acceptance_test.py.tmpl
+++ b/python/tests/toolchains/run_acceptance_test.py.tmpl
@@ -23,9 +23,8 @@
         os.chdir("%test_location%")
         rules_python_path = os.path.join(os.environ["TEST_SRCDIR"], "rules_python")
 
+        test_tmpdir = os.environ["TEST_TMPDIR"]
         if %is_windows%:
-            test_tmpdir = os.environ["TEST_TMPDIR"]
-
             home = os.path.join(test_tmpdir, "HOME")
             os.mkdir(home)
             os.environ["HOME"] = home
@@ -34,6 +33,16 @@
             os.mkdir(local_app_data)
             os.environ["LocalAppData"] = local_app_data
 
+        # Bazelisk requires a cache directory be set
+        os.environ["XDG_CACHE_HOME"] = os.path.join(test_tmpdir, "xdg-cache-home")
+
+        # Unset this so this works when called by Bazel's latest Bazel build
+        # pipeline. It sets the following combination, which interfere with each other:
+        # * --sandbox_tmpfs_path=/tmp
+        # * --test_env=USE_BAZEL_VERSION
+        # * USE_BAZEL_VERSION=/tmp/<something>
+        os.environ.pop("USE_BAZEL_VERSION", None)
+
         with open(".bazelrc", "w") as bazelrc:
             bazelrc.write(
                 os.linesep.join(
@@ -47,8 +56,11 @@
             )
 
     def test_match_toolchain(self):
-        stream = os.popen("bazel run @python//:python3 -- --version")
-        output = stream.read().strip()
+        output = subprocess.check_output(
+          f"bazel run @python//:python3 -- --version",
+          shell = True, # Shell needed to look up via PATH
+          text=True,
+        ).strip()
         self.assertEqual(output, "Python %python_version%")
 
         subprocess.run("bazel test //...", shell=True, check=True)