python-3.x - 自定义 Python 脚本和 PyTest 的 Yocto Bitbake 配方

标签 python-3.x pytest yocto bitbake

我有一个自定义的 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 依赖项。

最佳答案

首先我会看一下 poky/meta/recipes-devtools/python了解哪些 python 食谱可用(请注意您正在使用哪个版本)。

然后你可以添加对 native 版本的依赖,例如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 包添加到您自己的层中相对容易(只需查看提到的层中的食谱)。

关于python-3.x - 自定义 Python 脚本和 PyTest 的 Yocto Bitbake 配方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60840310/

相关文章:

python - pytest fixture 如何更改 fixture 范围

git - 如何管理Yocto项目的git仓库

boost - 在 yocto build 中包含特定的头文件

python - 在没有 collections.counter 的情况下根据整数值对字典进行排序

python - Python 中单个函数连续执行之间的时间

python - 子进程输出中未正确显示 Unicode 字符

python - 在 pytest 中执行teardown_method后测试失败

python - py.test : specifying python_files in the command line

embedded-linux - Yocto Jethro : no package provider for gdbserver

python-3.x - Python 3.7数据类: Raise error when assigning a value to undefined attribute