python - Jenkins Python 打印控制台输出

标签 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 中,我的构建执行 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/

相关文章:

python - 如何进行 Pandas 条件合并

python - 使用 DBI 模块将 Perl 代码转换为带有 MySQLdb 的 Python

python - Typeerror: object.__new__() takes no parameters (帮助)

PHP Cronjob 不执行

java - 我如何在 testNG 中使用 IAnnotationTransformer?

python - Flask 蓝图和登录重定向问题

linux - 如何解决 Kubernetes (Minikube) 上从外部到 pod 的 SCTP 连接上的对等方连接重置问题?

android -/dev/mem 和/dev/kmem 不存在?

python - 无法在 Whatsapp api 中找到发送按钮

selenium - 如何在 selenium 中搜索带有符号的元素