【问题标题】:Yocto Bitbake Recipe for Custom Python Script and PyTest用于自定义 Python 脚本和 PyTest 的 Yocto Bitbake 配方
【发布时间】:2020-07-05 11:53:09
【问题描述】:

我有一个自定义 Python Flask 应用程序,我使用 Yocto 和 Bitbake 为我的嵌入式目标构建它。 我还有一组测试用例,我在 Build Machine 上使用 PyTest 对应用程序运行。如果测试失败,我希望构建失败。

我正在寻找一种 Yocto 方法,将这些测试作为我的食谱的一部分作为自定义任务运行。到目前为止,谷歌搜索已经(异常)空了。

这是我迄今为止实现的——它可以工作,但它需要系统 Python3 和各种 pip 安装。理想情况下,需求将在 Yocto 中构建,但仅适用于主机而不是目标。我还没想好怎么做。

# Run the pytest test cases against the app code after it is installed
python do_run_pytest_testsuite(){

    # Change to the testing directory
    import os
    testDir = "%s"%(d.getVar('WORKDIR', True))
    os.chdir(testDir)

    # Run pytest execute the test suite
    from subprocess import Popen, PIPE
    with open("%s/TestOutput.txt"%(testDir), "w") as testReportFile:
        with Popen(['/usr/bin/python3','-m','pytest','-v','tests/test_app.py'], stdout=PIPE, bufsize=1, universal_newlines=True) as proc:
            for line in proc.stdout:
                testReportFile.write(line)

    # Get the return code
    if not proc.returncode == 0:

        # Force Failure
        bb.fatal("Test Cases Failed! ( %s )"%(testDir))

}
addtask run_pytest_testsuite before do_install after do_configure

我怎样才能在 Yocto 环境中完成这个自包含而不为目标板安装任何 PyTest 依赖项。

【问题讨论】:

    标签: python-3.x pytest yocto bitbake


    【解决方案1】:

    首先我会查看poky/meta/recipes-devtools/python 以了解可用的python 配方(注意您正在处理的版本)。

    然后您可以添加对本机版本食谱的依赖项,例如DEPENDS = "python3-native python3-yaml-native"(或运行 python 应用程序所需的任何包)

    然后添加一个运行你的应用程序的任务

    do_run_testsuite(){
      python3 ${WORKDIR}/test/test_app.py
    }
    addtask do_run_testsuite before do_install after do_configure
    

    也可以查看openembedded python layer

    如果您没有找到所需的所有依赖项,则将 pip 包添加到您自己的层相对容易(只需查看上述层中的配方)。

    【讨论】:

      猜你喜欢
      • 2018-08-20
      • 2019-11-07
      • 2019-11-19
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 2013-07-23
      • 1970-01-01
      • 2016-07-13
      相关资源
      最近更新 更多