suite1 = unittest.TestSuite()
suite2 = unittest.TestSuite()
# fill suites with test cases ...
result1 = unittest.TextTestRunner().run(suite1)
if result1.wasSuccessful():
unittest.TextTestRunner().run(suite2)
class MyTestCase(unittest.TestCase):
@unittest.skip("demonstrating skipping")
def test_nothing(self):
self.fail("shouldn't happen")
@unittest.skipIf(mylib.__version__ < (1, 3),
"not supported in this library version")
def test_format(self):
# Tests that work for only a certain version of the library.
pass
@unittest.skipUnless(sys.platform.startswith("win"), "requires Windows")
def test_windows_support(self):
# windows specific testing code
pass
如果您的测试是在
unittest
测试套件中构建的,则只有在第一个测试套件使用以下代码顺利通过时,才能执行长时间运行的测试套件:使用
doctest
如果您希望使用} documentation ),将以前测试的结果分配给一些变量,然后使用条件检查来确定是否要执行其他测试。就这样。在
doctest
,那么将其视为Python空闲(有关如何准备测试的提示,请参见^{不幸的是它与^{} 无关。在
使用
unittest
unittest
的命令行选项当遇到} (^{}) option 从命令行调用它,因此它在第一个错误或失败时停止测试运行。在
unittest
时,您仍然可以使用^{跳过测试
unittest
支持根据某些条件跳过测试(see documentation),或者当您知道测试已损坏并且不想将其视为失败时。请参阅基本跳过示例:有帮助吗?在
相关问题 更多 >
编程相关推荐