【问题标题】:Test output not visible in Jenkins build log测试输出在 Jenkins 构建日志中不可见
【发布时间】:2019-12-18 14:47:34
【问题描述】:

我希望看到来自 jenkins 构建日志中的 python 测试的标准输出。我正在 sh 脚本内的 Jenkins 管道中运行 pytest (==5.3.1):

stage('unit tests') {            
     print "starting unit tests"
     sh script: """
         source env-test/bin/activate && \
         python -m pytest -x -s src/test/test*.py
     """, returnStdout: true, returnStatus: true
}

请注意,我正在使用虚拟环境 (env-test) 运行我的测试。 不幸的是,Jenkins 日志没有显示我在测试中发送的输出:

def test_it(self):
   print('\nhello world')
   self.assertTrue(True)

但它只显示初始调用:

+ python -m pytest -x -s src/test/testModel.py
[Pipeline] }
[Pipeline] // stage

而我本地的 pycharm ide 和 gitbash 显示所有输出:

============================= test session starts =============================
platform win32 -- Python 3.6.4, pytest-5.3.1, py-1.8.0, pluggy-0.13.1 --     C:\...\Anaconda3\python.exe
cachedir: .pytest_cache
rootdir: C:\...\src\test
collecting ... collected 1 item

testModel.py::TestModel::test_it
PASSED                                  [100%]
hello world

============================== 1 passed in 0.57s ==============================

pytest 文档正在谈论Capturing of the stdout/stderr output。所以我尝试使用 -s 参数来禁用捕获但没有成功。

【问题讨论】:

    标签: python python-3.x jenkins pytest stdout


    【解决方案1】:

    问题是 groovy sh 脚本命令的returnStdout parameter

    returnStdout(可选)如果选中,则任务的标准输出为 作为步骤值作为字符串返回,而不是打印到 构建日志。 (如果有标准错误,仍将打印到 日志。)您经常希望在结果上调用 .trim() 以剥离 尾随换行符。类型:布尔型

    所以我只是从 sh 脚本命令中删除该选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-06
      • 2021-12-11
      • 2019-04-01
      • 1970-01-01
      • 2019-04-07
      • 1970-01-01
      • 1970-01-01
      • 2022-07-06
      相关资源
      最近更新 更多