Python unittest.expectedFailure() Examples

The following are 30 code examples for showing how to use unittest.expectedFailure(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module unittest , or try the search function .

Example 1
Project: jawfish   Author: war-and-code   File: test_result.py    License: MIT License 6 votes vote down vote up
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)) 
Example 2
Project: ironpython2   Author: IronLanguages   File: test_result.py    License: Apache License 2.0 6 votes vote down vote up
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)) 
Example 3
Project: BinderFilter   Author: dxwu   File: test_result.py    License: MIT License 6 votes vote down vote up
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)) 
Example 4
Project: oss-ftp   Author: aliyun   File: test_result.py    License: MIT License 6 votes vote down vote up
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)) 
Example 5
Project: pytest   Author: pytest-dev   File: test_unittest.py    License: MIT License 6 votes vote down vote up
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 
Example 6
Project: pytest   Author: pytest-dev   File: test_unittest.py    License: MIT License 6 votes vote down vote up
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 
Example 7
Project: Fluid-Designer   Author: Microvellum   File: test_case.py    License: GNU General Public License v3.0 6 votes vote down vote up
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) 
Example 8
Project: Fluid-Designer   Author: Microvellum   File: test_result.py    License: GNU General Public License v3.0 6 votes vote down vote up
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)) 
Example 9
Project: Fluid-Designer   Author: Microvellum   File: test_skipping.py    License: GNU General Public License v3.0 6 votes vote down vote up
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()) 
Example 10
Project: Fluid-Designer   Author: Microvellum   File: test_skipping.py    License: GNU General Public License v3.0 6 votes vote down vote up
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()) 
Example 11
Project: Imogen   Author: CedricGuillemet   File: test_case.py    License: MIT License 6 votes vote down vote up
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) 
Example 12
Project: Imogen   Author: CedricGuillemet   File: test_result.py    License: MIT License 6 votes vote down vote up
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)) 
Example 13
Project: Imogen   Author: CedricGuillemet   File: test_skipping.py    License: MIT License 6 votes vote down vote up
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()) 
Example 14
Project: Imogen   Author: CedricGuillemet   File: test_skipping.py    License: MIT License 6 votes vote down vote up
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()) 
Example 15
Project: ironpython3   Author: IronLanguages   File: test_case.py    License: Apache License 2.0 6 votes vote down vote up
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) 
Example 16
Project: ironpython3   Author: IronLanguages   File: test_result.py    License: Apache License 2.0 6 votes vote down vote up
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)) 
Example 17
Project: ironpython3   Author: IronLanguages   File: test_skipping.py    License: Apache License 2.0 6 votes vote down vote up
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()) 
Example 18
Project: ironpython3   Author: IronLanguages   File: test_skipping.py    License: Apache License 2.0 6 votes vote down vote up
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()) 
Example 19
Project: jawfish   Author: war-and-code   File: test_skipping.py    License: MIT License 5 votes vote down vote up
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()) 
Example 20
Project: jawfish   Author: war-and-code   File: test_skipping.py    License: MIT License 5 votes vote down vote up
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()) 
Example 21
Project: jawfish   Author: war-and-code   File: support.py    License: MIT License 5 votes vote down vote up
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 
Example 22
Project: networkx_viewer   Author: jsexauer   File: tests.py    License: GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 23
Project: verge3d-blender-addon   Author: Soft8Soft   File: support.py    License: GNU General Public License v3.0 5 votes vote down vote up
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 
Example 24
Project: verge3d-blender-addon   Author: Soft8Soft   File: base.py    License: GNU General Public License v3.0 5 votes vote down vote up
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func) 
Example 25
Project: verge3d-blender-addon   Author: Soft8Soft   File: base.py    License: GNU General Public License v3.0 5 votes vote down vote up
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func) 
Example 26
Project: verge3d-blender-addon   Author: Soft8Soft   File: base.py    License: GNU General Public License v3.0 5 votes vote down vote up
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func) 
Example 27
Project: verge3d-blender-addon   Author: Soft8Soft   File: base.py    License: GNU General Public License v3.0 5 votes vote down vote up
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3: 
Example 28
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func) 
Example 29
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func) 
Example 30
Project: misp42splunk   Author: remg427   File: base.py    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func)