unittest单元测试从TestSuit()中移除不需要执行的用例

:Test Suite:

源码中只提供了addtest的方法添加需要执行的用例到容器中,没有提供从容器中移走某个用例的方法,其实很好理解,只需要用到remove函数就能实现了。具体的改造也只是将append改成remove即可

    def delTest(self, test):
        # sanity checks
        if not hasattr(test, '__call__'):
            raise TypeError("{} is not callable".format(repr(test)))
        if isinstance(test, type) and issubclass(test,
                                                 (case.TestCase, TestSuite)):
            raise TypeError("TestCases and TestSuites must be instantiated "
                            "before passing them to addTest()")
        self._tests.remove(test)

猜你喜欢

转载自blog.csdn.net/zhouxuan623/article/details/83620353