运行bazel testBazel 时似乎默认为 Python 2,即使--python-version指定了标志
bazel test //... --python_version PY3
Run Code Online (Sandbox Code Playgroud)
INFO: From Testing //test:py-unit-tests:
==================== Test output for //test:py-unit-tests:
/usr/bin/env: 'python': No such file or directory
Run Code Online (Sandbox Code Playgroud)
这是我的构建文件
py_test(
name = "py-unit-tests",
srcs = glob(["unit/**/*.py"]),
deps = [
],
main = "unit/unit_test_runner.py",
timeout = "short",
)
Run Code Online (Sandbox Code Playgroud)
和测试文件
import sys
import unittest
class TestGeneration(unittest.TestCase):
def test_base(self):
pass
def test_urdf(self):
self.assertEqual("hello", 'test')
if __name__ == '__main__':
unittest.main()
Run Code Online (Sandbox Code Playgroud)
巴泽尔版本:3.3.1
其他值得注意的事情:
我的系统同时安装了 py2 和 py3
Py3 位于/usr/bin/python3
Py2 位于 /usr/bin/python2
没有/usr/bin/python
如https://github.com/bazelbuild/bazel/issues/11554中所述,问题是您的 Bazel python 存根有一个#!/usr/bin/env pythonshebang。如果python像您的情况一样不在 PATH 上,则存根将会失败。
以前唯一的解决方案是从pythonto添加符号链接python3,例如通过安装
sudo apt install python-is-python3
Run Code Online (Sandbox Code Playgroud)
然而,自从https://github.com/bazelbuild/bazel/commit/763dd0ce6e1644bf895231432f616427a11d385a登陆以来,存根 shebang 已变得可配置。您现在可以定义自己的py_runtime(https://docs.bazel.build/versions/main/be/python.html#py_runtime)
或者,自https://github.com/bazelbuild/bazel/commit/2945ef5072f659878dfd88b421c7b80aa4fb6c80起,默认的 shebang 也变成了#!/usr/bin/env python3
不过,这两个提交仅在 Bazel 5.0.0 中可用,因此现在您可能必须自己构建 Bazel 才能获取它们。