【问题标题】:Jenkins Python Print Console OutputJenkins Python 打印控制台输出
【发布时间】:2018-02-07 16:45:37
【问题描述】:

尝试通过测试用例在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 控制台输出不显示打印语句,但是当我在我的个人计算机上运行它时它会显示

【问题讨论】:

  • 您可能需要刷新输出。 sys.stdout.flush() 作为詹金斯控制台做任何它想做的事。
  • 您正在运行哪些操作系统?
  • 我在 Linux 上运行 jenkins

标签: python linux selenium jenkins


【解决方案1】:

你能在你的 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 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-05
    相关资源
    最近更新 更多