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