當前位置: 首頁>>代碼示例>>Python>>正文


Python unittest.expectedFailure方法代碼示例

本文整理匯總了Python中unittest.expectedFailure方法的典型用法代碼示例。如果您正苦於以下問題:Python unittest.expectedFailure方法的具體用法?Python unittest.expectedFailure怎麽用?Python unittest.expectedFailure使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在unittest的用法示例。


在下文中一共展示了unittest.expectedFailure方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testOldTestResult

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def testOldTestResult(self):
        class Test(unittest.TestCase):
            def testSkip(self):
                self.skipTest('foobar')
            @unittest.expectedFailure
            def testExpectedFail(self):
                raise TypeError
            @unittest.expectedFailure
            def testUnexpectedSuccess(self):
                pass

        for test_name, should_pass in (('testSkip', True),
                                       ('testExpectedFail', True),
                                       ('testUnexpectedSuccess', False)):
            test = Test(test_name)
            self.assertOldResultWarning(test, int(not should_pass)) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:18,代碼來源:test_result.py

示例2: test_unittest_expected_failure_for_failing_test_is_xfail

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_unittest_expected_failure_for_failing_test_is_xfail(testdir, runner):
    script = testdir.makepyfile(
        """
        import unittest
        class MyTestCase(unittest.TestCase):
            @unittest.expectedFailure
            def test_failing_test_is_xfail(self):
                assert False
        if __name__ == '__main__':
            unittest.main()
    """
    )
    if runner == "pytest":
        result = testdir.runpytest("-rxX")
        result.stdout.fnmatch_lines(
            ["*XFAIL*MyTestCase*test_failing_test_is_xfail*", "*1 xfailed*"]
        )
    else:
        result = testdir.runpython(script)
        result.stderr.fnmatch_lines(["*1 test in*", "*OK*(expected failures=1)*"])
    assert result.ret == 0 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:23,代碼來源:test_unittest.py

示例3: test_unittest_expected_failure_for_passing_test_is_fail

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_unittest_expected_failure_for_passing_test_is_fail(testdir, runner):
    script = testdir.makepyfile(
        """
        import unittest
        class MyTestCase(unittest.TestCase):
            @unittest.expectedFailure
            def test_passing_test_is_fail(self):
                assert True
        if __name__ == '__main__':
            unittest.main()
    """
    )

    if runner == "pytest":
        result = testdir.runpytest("-rxX")
        result.stdout.fnmatch_lines(
            ["*MyTestCase*test_passing_test_is_fail*", "*1 failed*"]
        )
    else:
        result = testdir.runpython(script)
        result.stderr.fnmatch_lines(["*1 test in*", "*(unexpected successes=1)*"])

    assert result.ret == 1 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:25,代碼來源:test_unittest.py

示例4: test_no_exception_leak

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_no_exception_leak(self):
        # Issue #19880: TestCase.run() should not keep a reference
        # to the exception
        class MyException(Exception):
            ninstance = 0

            def __init__(self):
                MyException.ninstance += 1
                Exception.__init__(self)

            def __del__(self):
                MyException.ninstance -= 1

        class TestCase(unittest.TestCase):
            def test1(self):
                raise MyException()

            @unittest.expectedFailure
            def test2(self):
                raise MyException()

        for method_name in ('test1', 'test2'):
            testcase = TestCase(method_name)
            testcase.run()
            self.assertEqual(MyException.ninstance, 0) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:test_case.py

示例5: test_expected_failure_with_wrapped_subclass

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_expected_failure_with_wrapped_subclass(self):
        class Foo(unittest.TestCase):
            def test_1(self):
                self.assertTrue(False)

        @unittest.expectedFailure
        class Bar(Foo):
            pass

        events = []
        result = LoggingResult(events)
        test = Bar("test_1")
        test.run(result)
        self.assertEqual(events,
                         ['startTest', 'addExpectedFailure', 'stopTest'])
        self.assertEqual(result.expectedFailures[0][0], test)
        self.assertTrue(result.wasSuccessful()) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:19,代碼來源:test_skipping.py

示例6: test_unexpected_success_subtests

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_unexpected_success_subtests(self):
        # Success in all subtests counts as the unexpected success of
        # the whole test.
        class Foo(unittest.TestCase):
            @unittest.expectedFailure
            def test_die(self):
                with self.subTest():
                    # This one succeeds
                    pass
                with self.subTest():
                    # So does this one
                    pass
        events = []
        result = LoggingResult(events)
        test = Foo("test_die")
        test.run(result)
        self.assertEqual(events,
                         ['startTest',
                          'addSubTestSuccess', 'addSubTestSuccess',
                          'addUnexpectedSuccess', 'stopTest'])
        self.assertFalse(result.failures)
        self.assertEqual(result.unexpectedSuccesses, [test])
        self.assertFalse(result.wasSuccessful()) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:25,代碼來源:test_skipping.py

示例7: test_expected_failure

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_expected_failure(self):
        class Foo(unittest.TestCase):
            @unittest.expectedFailure
            def test_die(self):
                self.fail("help me!")
        events = []
        result = LoggingResult(events)
        test = Foo("test_die")
        test.run(result)
        self.assertEqual(events,
                         ['startTest', 'addExpectedFailure', 'stopTest'])
        self.assertEqual(result.expectedFailures[0][0], test)
        self.assertTrue(result.wasSuccessful()) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:15,代碼來源:test_skipping.py

示例8: test_unexpected_success

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def test_unexpected_success(self):
        class Foo(unittest.TestCase):
            @unittest.expectedFailure
            def test_die(self):
                pass
        events = []
        result = LoggingResult(events)
        test = Foo("test_die")
        test.run(result)
        self.assertEqual(events,
                         ['startTest', 'addUnexpectedSuccess', 'stopTest'])
        self.assertFalse(result.failures)
        self.assertEqual(result.unexpectedSuccesses, [test])
        self.assertTrue(result.wasSuccessful()) 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:16,代碼來源:test_skipping.py

示例9: anticipate_failure

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def anticipate_failure(condition):
    """Decorator to mark a test that is known to be broken in some cases

       Any use of this decorator should have a comment identifying the
       associated tracker issue.
    """
    if condition:
        return unittest.expectedFailure
    return lambda f: f 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:11,代碼來源:support.py

示例10: setUpClass

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def setUpClass(cls):
        # Because edge out-c has a native width, we expect it to fail
        #  the base test_mark_edge. The test_mark_edge_pass case has been
        #  developed to test correct functionality
        cls.test_mark_edge = unittest.expectedFailure(cls.test_mark_edge) 
開發者ID:jsexauer,項目名稱:networkx_viewer,代碼行數:7,代碼來源:tests.py

示例11: expectedFailurePY3

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:6,代碼來源:base.py

示例12: expectedFailurePY26

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:6,代碼來源:base.py

示例13: expectedFailurePY27

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func) 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:6,代碼來源:base.py

示例14: expectedFailurePY2

# 需要導入模塊: import unittest [as 別名]
# 或者: from unittest import expectedFailure [as 別名]
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3: 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:9,代碼來源:base.py


注:本文中的unittest.expectedFailure方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。