在Python单元测试中运行测试用例时,有没有一种添加额外消息的方法?

时间:2019-12-19 08:25:03

标签: python-3.x python-unittest

我正在使用unittest在python中编写测试用例,并使用unittest-xml-reporting导出xml测试报告。我想在测试用例中自定义一些额外的消息,并在报告中导出。有什么好方法吗?

# app/test/main_test.py

class MainTest(unittest.TestCase):   
    @param("key","value") ## that I want
    def test_should_add_extra_message(self):
        self.assertEqual(2, 1+2)

# test_report.xml

<?xml version="1.0" encoding="utf-8"?>
<testsuites> 
  <testsuite errors="0" failures="0" file="main_test.py" name="main_test.MainTest-20191219160918" skipped="0" tests="1" time="0.006" timestamp="2019-12-19T16:09:18"> 
    <testcase classname="main_test.MainTest" file="app/test/main_test.py" line="18" name="test_should_add_extra_message" time="0.004" timestamp="2019-12-19T16:09:18"> 
      <system-out> <![CDATA[]]> </system-out>  
      <system-err> <![CDATA[]]> </system-err> 
    </testcase> 
  </testsuite> 
</testsuites>

我想在@param("key","value")文件显示中找到类似main_test.py的方式,test_report.xml应该在运行测试用例后获取该参数的键和值。

您对此有何建议?可以不使用unittest或unittest-xml-reporting。

谢谢!

0 个答案:

没有答案