unittest單元測試從TestSuit()中移除不需要執行的用例
阿新 • • 發佈:2018-12-26
: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)