Python 如何使用“保存日志信息”;鼻测试——用xunit“吗?”;?

Python 如何使用“保存日志信息”;鼻测试——用xunit“吗?”;?,python,logging,python-unittest,Python,Logging,Python Unittest,这是我的简单测试用例: import unittest import logging class TestAdd(unittest.TestCase): def setUp(self): logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %I:%M:%S', level=logging.INF

这是我的简单测试用例:

import unittest
import logging

class TestAdd(unittest.TestCase):

    def setUp(self):
        logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %I:%M:%S',
                            level=logging.INFO)

    def test_add(self):
        logging.info("Begin testing")
        self.assertEqual(1+1, 2, 'Failed to verify the add function.')
        logging.info("End testing")
如果我使用下面的cmd运行测试,那么我可以获得日志信息

    # nosetests test_add.py --nologcapture 
    2015-08-20 05:34:09 INFO Begin testing
    2015-08-20 05:34:09 INFO End testing

    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.001s

    OK
但是我真的想使用save这些信息到.xml文件中,所以我使用
#nosetests test\u add.py——与xunit一起生成一个名为
nosetests.xml
的文件。文件只告诉我我通过了测试,没有其他信息。如何将这些日志信息写入
nosetests.xml

试试看

$ nosetests --verbosity=3 -x --with-xunit
也可以使用nose.tools集合,而不是“import unittest”。 基本测试套件可能类似于:

import code  
import operator

m = code.Math()

def test_sum():  
    """Check is sum method is equivalent to operator"""
    eq_(m.sum(1, 1), operator.add(1, 1))
这是一篇好文章 试试看

$ nosetests --verbosity=3 -x --with-xunit
也可以使用nose.tools集合,而不是“import unittest”。 基本测试套件可能类似于:

import code  
import operator

m = code.Math()

def test_sum():  
    """Check is sum method is equivalent to operator"""
    eq_(m.sum(1, 1), operator.add(1, 1))
这是一篇好文章