Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
226 views
in Technique[技术] by (71.8m points)

python - Prevent bazel py_test from implicitly depending on files from the same directory

My bazel py_test rule seems to be able to import files in the same folder for which there was no dependency declared. Is there a way to prevent this? I am running bazel 3.7.2 on linux. Here is an example:

# Note that foo_test doesn't declare :foo as a dependency
$ cat BUILD
py_library(
    name = "foo",
    srcs = ["foo.py"],
)

py_test(
    name = "foo_test",
    srcs = ["foo_test.py"],
)

$ cat foo.py
def foo():
    print("hello")

# However, I can still import and use the library
$ cat foo_test.py
import foo
foo.foo()

$ bazel-3.7.2-linux-x86_64 test :foo_test
<snip>
//:foo_test                                                              PASSED in 0.3s

Is there a configuration option that would prevent the foo_test rule from implicitly picking up foo.py?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...