Python unittest 模块,expectedFailure() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用unittest.expectedFailure()

项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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))
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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))
项目:varapp-backend-py    作者:varapp    | 项目源码 | 文件源码
def test_compound_unaffected_compound(self):
        """Unaffected compound: exclude (the disease is not due to a compound)"""
        genotypes = array(
            [[2,1, 2,2, 1,1],
             [2,1, 2,2, 2,1],
             [1,2, 2,2, 1,1],
             [1,2, 2,2, 2,1]], dtype=DTYPE)
        variants = VariantsCollection([
            Variant(variant_id=1, start=0, gene_symbol='B'),  # mother 1
            Variant(variant_id=2, start=1, gene_symbol='B'),  # mother 2 + unaffected 1
            Variant(variant_id=3, start=2, gene_symbol='B'),  # father 1
            Variant(variant_id=4, start=3, gene_symbol='B'),  # father 2 + unaffected 2
        ])
        var = GenotypesFilterCompoundHeterozygous(self.ss).apply(variants, genotypes).variants
        self.assertEqual(len(var), 2)  # would be 4, but here we exclude an entire pair (2 variants):
            # one of the ends of the unaffected pair must be non-deleterious,
            # so no affected pair containing one of them can have both alleles deficient.
            # Thus a single pair remains -> 2 variants.

    # Updated by the change that allows only one same compound for all affected samples.
    #@unittest.expectedFailure
    # To my opinion it is ok if different compound scenarios work in different affected samples
    # i.e. two samples can be affected but each one with a different compound pair.
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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))
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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))
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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))
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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))
项目:pefile.pypy    作者:cloudtracer    | 项目源码 | 文件源码
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))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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())
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_expected_failure_subtests(self):
        # A failure in any subtest counts as the expected failure of the
        # whole test.
        class Foo(unittest.TestCase):
            @unittest.expectedFailure
            def test_die(self):
                with self.subTest():
                    # This one succeeds
                    pass
                with self.subTest():
                    self.fail("help me!")
                with self.subTest():
                    # This one doesn't get executed
                    self.fail("shouldn't come here")
        events = []
        result = LoggingResult(events)
        test = Foo("test_die")
        test.run(result)
        self.assertEqual(events,
                         ['startTest', 'addSubTestSuccess',
                          'addExpectedFailure', 'stopTest'])
        self.assertEqual(len(result.expectedFailures), 1)
        self.assertIs(result.expectedFailures[0][0], test)
        self.assertTrue(result.wasSuccessful())
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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())
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
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)
项目:django-tornado-websockets    作者:Kocal    | 项目源码 | 文件源码
def test_on_message_when_nonexistent_event(self):
        ws_connection = yield self.ws_connect('/ws/test')

        # Test when the event is not binded
        self.assertDictEqual(self.ws.events, {'hello': ANY})

        ws_connection.write_message(json_encode({
            'event': 'bye',
            'data': {'message': 'Bye !'}
        }))

        # Throw TimeoutError and/or StopIteration, because WebSocketHandler.on_message() does not send
        # any message when the client send a nonexistent event ('bye' in our case).
        # Also, I don't know how catch them, because self.assertRaises() and try/catch don't work.
        # So I use @unittest.expectedFailure here, but it's a bit dirty imo.
        yield ws_connection.read_message()
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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))
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_expected_failure_subtests(self):
        # A failure in any subtest counts as the expected failure of the
        # whole test.
        class Foo(unittest.TestCase):
            @unittest.expectedFailure
            def test_die(self):
                with self.subTest():
                    # This one succeeds
                    pass
                with self.subTest():
                    self.fail("help me!")
                with self.subTest():
                    # This one doesn't get executed
                    self.fail("shouldn't come here")
        events = []
        result = LoggingResult(events)
        test = Foo("test_die")
        test.run(result)
        self.assertEqual(events,
                         ['startTest', 'addSubTestSuccess',
                          'addExpectedFailure', 'stopTest'])
        self.assertEqual(len(result.expectedFailures), 1)
        self.assertIs(result.expectedFailures[0][0], test)
        self.assertTrue(result.wasSuccessful())
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
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())
项目:GSM-scanner    作者:yosriayed    | 项目源码 | 文件源码
def test_unittest_unexpected_failure(testdir):
    testdir.makepyfile("""
        import unittest
        class MyTestCase(unittest.TestCase):
            @unittest.expectedFailure
            def test_func1(self):
                assert 0
            @unittest.expectedFailure
            def test_func2(self):
                assert 1
    """)
    result = testdir.runpytest("-rxX")
    result.stdout.fnmatch_lines([
        "*XFAIL*MyTestCase*test_func1*",
        "*XPASS*MyTestCase*test_func2*",
        "*1 xfailed*1 xpass*",
    ])
项目:Tinychat-Bot--Discontinued    作者:Tinychat    | 项目源码 | 文件源码
def expectedFailureIfAppengine(func):
    try:
        from google import appengine  # noqa
    except ImportError:
        return func
    else:
        import os

        if os.environ.get('SERVER_SOFTWARE', None) is None:
            return func

        return unittest.expectedFailure(func)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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())
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
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())
项目:py2rb    作者:naitoh    | 项目源码 | 文件源码
def compile_and_run_file_failing_test(*a, **k):
    """Turn a test to a failing test"""
    _class = compile_and_run_file_test(*a, **k)

    class FailingTest(_class):
        """Failing test"""
        @unittest.expectedFailure
        def runTest(self):
            return super(FailingTest, self).runTest()

    return FailingTest
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func)
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func)
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func)
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3:
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
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
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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())
项目:zippy    作者:securesystemslab    | 项目源码 | 文件源码
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())
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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())
项目:oil    作者:oilshell    | 项目源码 | 文件源码
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())
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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())
项目:python2-tracer    作者:extremecoders-re    | 项目源码 | 文件源码
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())
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3:
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
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
项目:Learning-Python-Application-Development    作者:PacktPublishing    | 项目源码 | 文件源码
def test_2(self):
        """Illustrate how to use unittest.expectedFailure"""
        print("in test_2")
        self.assertEqual(1 + 1, 3)

    #@unittest.skip("Skipping test_1")
项目:Learning-Python-Application-Development    作者:PacktPublishing    | 项目源码 | 文件源码
def test_2(self):
        """Illustrate how to use unittest.expectedFailure"""
        print("in test_2")
        self.assertEqual(1 + 1, 3)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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())
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
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())
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func)
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func)
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func)
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3:
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
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
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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())
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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())
项目:web_ctp    作者:molebot    | 项目源码 | 文件源码
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