gpt4 book ai didi

python - Jenkins Python 打印控制台输出

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:03 28 4
gpt4 key购买 nike

尝试通过以下测试用例在 Jenkins 中打印文本“已登录”:

import unittest
from #path.to.methods import method
Class TC1(unittest.TestCase):
def test_tc01(self):
self.driver = webdriver.chrome()
driver = method(self.driver)
driver.login()
print ("Logged in")

在 Jenkins 中,我的 Build Execute Shell 命令是这样的:

cd path/to/test
py.test --cov

目前 Jenkins 控制台输出不显示打印语句,但是当我在我的个人计算机上运行它时它会显示

最佳答案

你能不能在你的 python 脚本的开头添加这个:

#!/usr/bin/env python -u

-u 的作用:

 python -u
-u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put
stdin, stdout and stderr in binary mode. Note that there is internal buffering in xreadlines(),
readlines() and file-object iterators ("for line in sys.stdin") which is not influenced by this
option. To work around this, you will want to use "sys.stdin.readline()" inside a "while 1:"
loop.

或:

import unittest
import sys #<--this
from #path.to.methods import method
Class TC1(unittest.TestCase):
def test_tc01(self):
self.driver = webdriver.chrome()
driver = method(self.driver)
driver.login()
print ("Logged in")
sys.stdout.flush() #<--and this

关于python - Jenkins Python 打印控制台输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48669047/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com