Skip to content

Commit

Permalink
Make toolchain acceptance tests work with latest Bazel build CI pipel…
Browse files Browse the repository at this point in the history
…ine (#1062)
  • Loading branch information
rickeylev committed Feb 11, 2023
1 parent 6905e63 commit fab77f7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions python/tests/toolchains/run_acceptance_test.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ class TestPythonVersion(unittest.TestCase):
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
Expand All @@ -34,6 +33,16 @@ class TestPythonVersion(unittest.TestCase):
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(
Expand All @@ -47,8 +56,11 @@ class TestPythonVersion(unittest.TestCase):
)

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)
Expand Down

0 comments on commit fab77f7

Please sign in to comment.