Python鼻子:使用多进程插件将测试结果记录到文件

Python鼻子:使用多进程插件将测试结果记录到文件

问题描述:

我试图将我的测试输出记录到文件以及同时运行它们。 对于这个我试图使用多进程插件和xunit插件。Python鼻子:使用多进程插件将测试结果记录到文件

我知道他们不一起工作,xunit没有记录任何东西,因为mutiprocess不直接发送输出。

https://github.com/nose-devs/nose/issues/2

什么进出口寻找任何替代,让我写下输出到文件。 原因是我正在运行硒测试,每次我得到一个错误,stacktrace是如此之大,stdout基本上完全填写。减少的东西也可能有所帮助,硒的文档对于如何配置日志记录输出相当稀少。

我也试过标准输出的一个非常基本的重定向:

#nosetests > file.txt 

但是,这并不工作要么。

如果你想使用基本重定向从外壳,你可以做

nosetests &> output.txt 

但基于你的问题似乎你宁愿做这样的事情:

$nosetests --processes 4 --with-xunit --xunit-file=test_output.xml 

完整的示例

$ls 
test_nose.py test_nose.pyc 

$cat test_nose.py 

import sys 
import os 
import time 

def setUp(): 
    pass 

def test_1(): 
    time.sleep(5) 
    with open('test_pid_' + str(os.getpid()), 'w') as f: 
     f.write(str(os.getpid()) + '\n') 

def test_2(): 
    time.sleep(5) 
    with open('test_pid_' + str(os.getpid()), 'w') as f: 
     f.write(str(os.getpid()) + '\n') 

def test_3(): 
    time.sleep(5) 
    with open('test_pid_' + str(os.getpid()), 'w') as f: 
     f.write(str(os.getpid()) + '\n') 

def test_4(): 
    time.sleep(5) 
    with open('test_pid_' + str(os.getpid()), 'w') as f: 
     f.write(str(os.getpid()) + '\n') 

def tearDown(): 
    pass 

$ nosetests --processes 4 --with-xunit --xunit-file=test_output.xml 
.... 
---------------------------------------------------------------------- 
Ran 4 tests in 5.223s 

OK 

$ ls 
test_nose.py test_output.xml test_pid_55247 test_pid_55249 
test_nose.pyc test_pid_55246 test_pid_55248 

$ cat test_pid* 
55246 
55247 
55248 
55249 

$ xmllint -format test_output.xml 
<?xml version="1.0" encoding="UTF-8"?> 
<testsuite name="nosetests" tests="0" errors="0" failures="0" skip="0"/> 

看起来它不起作用你说:)

$nosetests --processes 4 &> output.txt 

而且

$nosetests --with-xunit --xunit-file=test_output.xml 

做。

参考文献:

Redirect stderr and stdout in a Bash script

$man xmllint 

$nosetests -h 
+0

非常感谢,它完美的作品! – dgrandes 2012-04-18 15:44:58