Jenkins Python Print Console输出

时间:2018-02-07 16:45:37

标签: python linux selenium jenkins

尝试打印文字"登录"在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控制台输出不会显示print语句,但是当我在个人计算机上运行时它会显示

1 个答案:

答案 0 :(得分:2)

你可以在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