当前位置: 首页>>代码示例>>Python>>正文


Python Xunit.addError方法代码示例

本文整理汇总了Python中nose.plugins.xunit.Xunit.addError方法的典型用法代码示例。如果您正苦于以下问题:Python Xunit.addError方法的具体用法?Python Xunit.addError怎么用?Python Xunit.addError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nose.plugins.xunit.Xunit的用法示例。


在下文中一共展示了Xunit.addError方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestXMLOutputWithXML

# 需要导入模块: from nose.plugins.xunit import Xunit [as 别名]
# 或者: from nose.plugins.xunit.Xunit import addError [as 别名]
class TestXMLOutputWithXML(unittest.TestCase):
    
    def setUp(self):
        self.xmlfile = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 
                            'support', 'xunit.xml'))
        parser = optparse.OptionParser()
        self.x = Xunit()
        self.x.add_options(parser, env={})
        (options, args) = parser.parse_args([
            "--with-xunit",
            "--xunit-file=%s" % self.xmlfile
        ])
        self.x.configure(options, Config())
        
        try:
            import xml.etree.ElementTree
        except ImportError:
            self.ET = False
        else:
            self.ET = xml.etree.ElementTree
    
    def tearDown(self):
        os.unlink(self.xmlfile)
    
    def get_xml_report(self):
        class DummyStream:
            pass
        self.x.report(DummyStream())
        f = open(self.xmlfile, 'r')
        return f.read()
        f.close()
            
    def test_addFailure(self):
        test = mktest()
        self.x.startTest(test)
        try:
            raise AssertionError("one is not 'equal' to two")
        except AssertionError:
            some_err = sys.exc_info()
            
        self.x.addFailure(test, some_err)
        
        result = self.get_xml_report()
        print result
        
        if self.ET:
            tree = self.ET.fromstring(result)
            eq_(tree.attrib['name'], "nosetests")
            eq_(tree.attrib['tests'], "1")
            eq_(tree.attrib['errors'], "0")
            eq_(tree.attrib['failures'], "1")
            eq_(tree.attrib['skip'], "0")
        
            tc = tree.find("testcase")
            eq_(tc.attrib['classname'], "test_xunit.TC")
            eq_(tc.attrib['name'], "test_xunit.TC.runTest")
            assert int(tc.attrib['time']) >= 0
        
            err = tc.find("failure")
            eq_(err.attrib['type'], "exceptions.AssertionError")
            err_lines = err.text.strip().split("\n")
            eq_(err_lines[0], 'Traceback (most recent call last):')
            eq_(err_lines[-1], 'AssertionError: one is not \'equal\' to two')
            eq_(err_lines[-2], '    raise AssertionError("one is not \'equal\' to two")')
        else:            
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert '<testsuite name="nosetests" tests="1" errors="0" failures="1" skip="0">' in result
            assert '<testcase classname="test_xunit.TC" name="test_xunit.TC.runTest"' in result
            assert '<failure type="exceptions.AssertionError">' in result
            assert 'AssertionError: one is not &#39;equal&#39; to two' in result
            assert 'AssertionError(&quot;one is not &#39;equal&#39; to two&quot;)' in result
            assert '</failure></testcase></testsuite>' in result
            
    def test_addFailure_early(self):
        test = mktest()
        try:
            raise AssertionError("one is not equal to two")
        except AssertionError:
            some_err = sys.exc_info()
        
        # add failure without startTest, due to custom TestResult munging?
        self.x.addFailure(test, some_err)
        
        result = self.get_xml_report()
        print result
        
        if self.ET:
            tree = self.ET.fromstring(result)
            tc = tree.find("testcase")
            eq_(tc.attrib['time'], "0")
        else:
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert ('<testcase classname="test_xunit.TC" '
                    'name="test_xunit.TC.runTest" time="0">') in result
    
    def test_addError(self):
        test = mktest()
#.........这里部分代码省略.........
开发者ID:LucianU,项目名称:kuma-lib,代码行数:103,代码来源:test_xunit.py

示例2: TestXMLOutputWithXML

# 需要导入模块: from nose.plugins.xunit import Xunit [as 别名]
# 或者: from nose.plugins.xunit.Xunit import addError [as 别名]

#.........这里部分代码省略.........
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert '<testsuite name="nosetests" tests="1" errors="0" failures="1" skip="0">' in result
            assert '<testcase classname="test_xunit.TC" name="runTest"' in result
            assert '<failure type="exceptions.AssertionError"' in result
            assert "AssertionError: one is not 'equal' to two" in result
            assert "AssertionError(\"one is not 'equal' to two\")" in result
            assert '</failure></testcase></testsuite>' in result

    def test_addFailure_early(self):
        test = mktest()
        try:
            raise AssertionError("one is not equal to two")
        except AssertionError:
            some_err = sys.exc_info()

        # add failure without startTest, due to custom TestResult munging?
        self.x.addFailure(test, some_err)

        result = self.get_xml_report()
        print result

        if self.ET:
            tree = self.ET.fromstring(result)
            tc = tree.find("testcase")
            assert time_taken.match(tc.attrib['time']), (
                        'Expected decimal time: %s' % tc.attrib['time'])
        else:
            # this is a dumb test for 2.4-
            assert '<?xml version="1.0" encoding="UTF-8"?>' in result
            assert ('<testcase classname="test_xunit.TC" '
                    'name="runTest" time="0') in result

    def test_addError(self):
        test = mktest()
        self.x.beforeTest(test)
        try:
            raise RuntimeError("some error happened")
        except RuntimeError:
            some_err = sys.exc_info()

        self.x.addError(test, some_err)

        result = self.get_xml_report()
        print result

        if self.ET:
            tree = self.ET.fromstring(result)
            eq_(tree.attrib['name'], "nosetests")
            eq_(tree.attrib['tests'], "1")
            eq_(tree.attrib['errors'], "1")
            eq_(tree.attrib['failures'], "0")
            eq_(tree.attrib['skip'], "0")

            tc = tree.find("testcase")
            eq_(tc.attrib['classname'], "test_xunit.TC")
            eq_(tc.attrib['name'], "runTest")
            assert time_taken.match(tc.attrib['time']), (
                        'Expected decimal time: %s' % tc.attrib['time'])

            err = tc.find("error")
            eq_(err.attrib['type'], "%s.RuntimeError" % (RuntimeError.__module__,))
            err_lines = err.text.strip().split("\n")
            eq_(err_lines[0], 'Traceback (most recent call last):')
            eq_(err_lines[-1], 'RuntimeError: some error happened')
            eq_(err_lines[-2], '    raise RuntimeError("some error happened")')
开发者ID:ahmedelsb,项目名称:nose,代码行数:70,代码来源:test_xunit.py


注:本文中的nose.plugins.xunit.Xunit.addError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。