From b1be2de85db6ee85e0ffcf098137ee4ad1e0bb0d Mon Sep 17 00:00:00 2001 From: Richard Levasseur Date: Wed, 3 Jan 2024 13:14:01 -0800 Subject: [PATCH] python: fix bazel py_test testSmoke for Python 3.11+ The test was failing because the `b.py` file couldn't be imported because, starting with Python 3.11, the `PYTHONSAFEPATH` environment variable (set by the bootstrap startup) is respected. This setting inhibits the default Python behavior of adding the main script's directory to sys.path. To fix, use `py_library.imports` to explicitly add the necessary directory to `sys.path`. Fixes https://github.com/bazelbuild/bazel/issues/20660 --- src/test/py/bazel/py_test.py | 2 +- src/test/py/bazel/test_base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/py/bazel/py_test.py b/src/test/py/bazel/py_test.py index 83e45a16d103f6..6c130a85d1b88e 100644 --- a/src/test/py/bazel/py_test.py +++ b/src/test/py/bazel/py_test.py @@ -28,7 +28,7 @@ def createSimpleFiles(self): 'a/BUILD', [ 'py_binary(name="a", srcs=["a.py"], deps=[":b"])', - 'py_library(name="b", srcs=["b.py"])', + 'py_library(name="b", srcs=["b.py"], imports=["."])', ]) self.ScratchFile( diff --git a/src/test/py/bazel/test_base.py b/src/test/py/bazel/test_base.py index ead5fcc4b9c753..49a4a6506fb1ff 100644 --- a/src/test/py/bazel/test_base.py +++ b/src/test/py/bazel/test_base.py @@ -562,7 +562,7 @@ def RunProgram( ] if not allow_failure: - self.AssertExitCode(exit_code, 0, stderr_lines) + self.AssertExitCode(exit_code, 0, stderr_lines, stdout_lines) return exit_code, stdout_lines, stderr_lines