且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以在Bazel测试中使用Python调试器吗

更新时间:2022-02-08 00:11:11

您可以使用--run_under标志进行操作,如上所述.重要的是要注意,您需要在安装python时指向pdb.py.要找到指向的位置,可以执行以下操作:

You can do this using the --run_under flag, as mentioned. It's important to note that you need to point to the pdb.py for your python install. To find where to point to, you can do the following:

检查python版本的安装位置.应该使用python2.7或python3.6之类的东西,而不仅仅是python或python3,因为它们通常只是符号链接.

Check where your python version is installed. This should be using something like python2.7, or python3.6, not just python or python3, as those are frequently just symlinks.

$ which python3.6
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

请注意,这是二进制文件所在的位置,而我们要指向一个库文件.为此,将最后一个bin替换为lib,然后指定所需的文件,如下所示:

Note that this is where the binary is located, while we want to point to a library file. To do so, replace the last bin with lib, and specify the desired file, something like this:

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py

现在,您可以像这样运行目标:

Now you can run your targets like this:

bazel run --run_under="/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/pdb.py"