尝试通过测试用例在 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 中,我的构建执行 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/