问题 Python Nose:使用Multiprocess Plugin将测试结果记录到文件中


我试图将我的测试输出记录到文件以及同时运行它们。 为此,我试图使用多进程插件和xunit插件。

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

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

我正在寻找的是允许我将输出写入文件的任何替代方案。 原因是我正在运行Selenium Tests,每次我收到错误时,堆栈跟踪都非常大,以至于stdout基本上已经完全填满了。 减轻的东西也可能有所帮助,关于如何配置日志输出的selenium文档非常缺乏。

我还尝试了一个非常基本的stdout重定向:

#nosetests > file.txt

但那也不起作用。


11460
2018-02-06 15:11


起源



答案:


如果要从shell使用基本重定向,则可以执行此操作

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

做。

参考文献:

在Bash脚本中重定向stderr和stdout

$man xmllint

$nosetests -h

15
2018-03-30 02:24



非常感谢,它完美无缺! - dgrandes


答案:


如果要从shell使用基本重定向,则可以执行此操作

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

做。

参考文献:

在Bash脚本中重定向stderr和stdout

$man xmllint

$nosetests -h

15
2018-03-30 02:24



非常感谢,它完美无缺! - dgrandes