【发布时间】: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