【问题标题】:Using binary in python test in bazel在 bazel 的 python 测试中使用二进制文件
【发布时间】:2023-03-09 17:01:01
【问题描述】:

我想为我的 C++ 二进制文件编写一些端到端测试,这将提供一些输入文件并从标准输出读取输出并断言它是正确的。我写了一个简单的 python 测试,它工作正常,现在我尝试让它与 bazel 一起工作。我将 py_test 添加到 bazel 并构建,但我无法指定 cc_binary 依赖于该目标(bazel 抱怨)。如果我不单独运行cc_binary 的构建命令,python 测试将看不到bazel-bin 中的二进制文件。如何在运行 py_test 之前强制构建我的 cc_binary

【问题讨论】:

    标签: bazel


    【解决方案1】:

    您可以将二进制文件添加为数据依赖项。有关详细信息,请参阅the encyclopedia,但它基本上看起来像:

    cc_binary(
        name = "my-bin",
        srcs = ["bin.cc"],
    )
    
    py_test(
        name = "my-test",
        srcs = ["my_test.py"],
        data = [":my-bin"],
        # any other attributes you need...
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-15
      • 2013-04-10
      • 1970-01-01
      • 2020-01-29
      • 1970-01-01
      • 2014-02-15
      • 2021-11-20
      • 1970-01-01
      相关资源
      最近更新 更多