修改testtools框架,将测试结果显示用例注释名字
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
:ivar force_failure: Force testtools.RunTest to fail the test after the test has completed.
:cvar run_tests_with: A factory to make the ``RunTest`` to run tests with. Defaults to ``RunTest``. The factory is expected to take a test case and an optional list of exception handlers.
修改 testtools框架,将测试结果显示用例注释名字
在之前介绍的测试框架中,发现测试结果中显示的都是测试用例的函数名,并没有将注释显示出来
这很不符合国人使用阿,没办法,自己动手来改改吧
首先,testtools是继承unittest的一个工具,所以应该存在unittest TestCase的相关函数
File "test_case\testtools_learn.py", line 34, in te st_case_2
assert 2 == 3 AssertionError
----------------------------------------------------------------------
"""
...... ......
def shortDescription(self): return self.id()
原来这里没显示注释,那来改改吧,直接上代码
def __init__(self, *args, **kwargs): """Construct a TestCase.
:param testMethod: The name of the method to run. :keyword runTest: Optional class to use to execute the test. If not
看看testtools.testcase原码吧,发现,不显示注释的奥秘在这里
class TestCase(unittest.TestCase): """Extensions to the basic TestCase.
:ivar exception_handlers: Exceptions to catch from setUp, runTest and tearDown. This list is able to be modified at any time and consists of (exception_class, handler(case, result, exception_value)) pairs.
supplied ``RunTest`` is used. The instance to be used is created when run() is invoked, so will be fresh each time. Overrides ``TestCase.run_tests_with`` if given. """ runTest = kwargs.pop('runTest', None) super(TestCase, self).__init__(*args, **kwargs) self._reset() test_method = self._get_test_method() if runTest is None: runTest = getattr(
def shortDescription(self): #return self.id() doc = self._testMethodDoc return doc and doc.split("\n")[0].strip() or None
这里再改成这样。
再次运行,结果如下:
====================================================================== FAIL: i dont konw ---------------------------------------------------------------------_StringException: Traceback (most recent call last):
很好,显示为用例的注释名了。
test_method, '_run_test_with', self.run_tests_with) self.__RunTest = runTest self._testMethodDoc = test_methMethodDoc = test_method.__doc__
:cvar run_tests_with: A factory to make the ``RunTest`` to run tests with. Defaults to ``RunTest``. The factory is expected to take a test case and an optional list of exception handlers.
修改 testtools框架,将测试结果显示用例注释名字
在之前介绍的测试框架中,发现测试结果中显示的都是测试用例的函数名,并没有将注释显示出来
这很不符合国人使用阿,没办法,自己动手来改改吧
首先,testtools是继承unittest的一个工具,所以应该存在unittest TestCase的相关函数
File "test_case\testtools_learn.py", line 34, in te st_case_2
assert 2 == 3 AssertionError
----------------------------------------------------------------------
"""
...... ......
def shortDescription(self): return self.id()
原来这里没显示注释,那来改改吧,直接上代码
def __init__(self, *args, **kwargs): """Construct a TestCase.
:param testMethod: The name of the method to run. :keyword runTest: Optional class to use to execute the test. If not
看看testtools.testcase原码吧,发现,不显示注释的奥秘在这里
class TestCase(unittest.TestCase): """Extensions to the basic TestCase.
:ivar exception_handlers: Exceptions to catch from setUp, runTest and tearDown. This list is able to be modified at any time and consists of (exception_class, handler(case, result, exception_value)) pairs.
supplied ``RunTest`` is used. The instance to be used is created when run() is invoked, so will be fresh each time. Overrides ``TestCase.run_tests_with`` if given. """ runTest = kwargs.pop('runTest', None) super(TestCase, self).__init__(*args, **kwargs) self._reset() test_method = self._get_test_method() if runTest is None: runTest = getattr(
def shortDescription(self): #return self.id() doc = self._testMethodDoc return doc and doc.split("\n")[0].strip() or None
这里再改成这样。
再次运行,结果如下:
====================================================================== FAIL: i dont konw ---------------------------------------------------------------------_StringException: Traceback (most recent call last):
很好,显示为用例的注释名了。
test_method, '_run_test_with', self.run_tests_with) self.__RunTest = runTest self._testMethodDoc = test_methMethodDoc = test_method.__doc__