Python unittest2.expectedFailure() Examples

The following are 30 code examples of unittest2.expectedFailure(). 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 also want to check out all available functions/classes of the module unittest2 , or try the search function .
Example #1
Source File: test_junitxml.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 7 votes vote down vote up
def test_unexpected_success_test(self):
        class Succeeds(unittest.TestCase):
            def test_me(self):
                pass
            try:
                test_me = unittest.expectedFailure(test_me)
            except AttributeError:
                pass # Older python - just let the test pass
        self.result.startTestRun()
        Succeeds("test_me").run(self.result)
        self.result.stopTestRun()
        output = self.get_output()
        expected = """<testsuite errors="0" failures="1" name="" tests="1" time="0.000">
<testcase classname="junitxml.tests.test_junitxml.Succeeds" name="test_me" time="0.000">
<failure type="unittest.case._UnexpectedSuccess"/>
</testcase>
</testsuite>
"""
        expected_old = """<testsuite errors="0" failures="0" name="" tests="1" time="0.000">
<testcase classname="junitxml.tests.test_junitxml.Succeeds" name="test_me" time="0.000"/>
</testsuite>
"""
        if output != expected_old:
            self.assertEqual(expected, output) 
Example #2
Source File: test_unittest2_with.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 6 votes vote down vote up
def test_old_testresult(self):
        class Test(unittest2.TestCase):
            def testSkip(self):
                self.skipTest('foobar')
            def testExpectedFail(self):
                raise TypeError
            testExpectedFail = unittest2.expectedFailure(testExpectedFail)
            def testUnexpectedSuccess(self):
                pass
            testUnexpectedSuccess = unittest2.expectedFailure(testUnexpectedSuccess)
        
        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
Source File: base.py    From gimp-plugin-export-layers with 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 #4
Source File: base.py    From gimp-plugin-export-layers with 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 #5
Source File: base.py    From arissploit with 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 #6
Source File: base.py    From arissploit with 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 #7
Source File: support.py    From arissploit with 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 #8
Source File: base.py    From Tautulli with 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 #9
Source File: base.py    From Tautulli with 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 #10
Source File: base.py    From Tautulli with 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 #11
Source File: support.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 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 #12
Source File: base.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func) 
Example #13
Source File: base.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func) 
Example #14
Source File: base.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func) 
Example #15
Source File: base.py    From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3: 
Example #16
Source File: base.py    From Tautulli with 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 #17
Source File: base.py    From gimp-plugin-export-layers with 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 #18
Source File: base.py    From gimp-plugin-export-layers with 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 #19
Source File: support.py    From gimp-plugin-export-layers with 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 #20
Source File: test_skipping.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def test_unexpected_success(self):
        class Foo(unittest2.TestCase):
            def test_die(self):
                pass
            test_die = unittest2.expectedFailure(test_die)
        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
Source File: test_skipping.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def test_expected_failure(self):
        class Foo(unittest2.TestCase):
            def test_die(self):
                self.fail("help me!")
            test_die = unittest2.expectedFailure(test_die)
        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 #22
Source File: test_junitxml.py    From ConTroll_Remote_Access_Trojan with Apache License 2.0 5 votes vote down vote up
def test_expected_failure_test(self):
        expected_failure_support = [True]
        class ExpectedFail(unittest.TestCase):
            def test_me(self):
                self.fail("fail")
            try:
                test_me = unittest.expectedFailure(test_me)
            except AttributeError:
                # Older python - just let the test fail
                expected_failure_support[0] = False
        self.result.startTestRun()
        ExpectedFail("test_me").run(self.result)
        self.result.stopTestRun()
        output = self.get_output()
        expected = """<testsuite errors="0" failures="0" name="" tests="1" time="0.000">
<testcase classname="junitxml.tests.test_junitxml.ExpectedFail" name="test_me" time="0.000"/>
</testsuite>
"""
        expected_old = """<testsuite errors="0" failures="1" name="" tests="1" time="0.000">
<testcase classname="junitxml.tests.test_junitxml.ExpectedFail" name="test_me" time="0.000">
<failure type="AssertionError">failure</failure>
</testcase>
</testsuite>
"""
        if expected_failure_support[0]:
            self.assertEqual(expected, output)
        else:
            self.assertEqual(expected_old, output) 
Example #23
Source File: __init__.py    From boardfarm with BSD 3-Clause Clear License 5 votes vote down vote up
def expectedFailureIf(test):
    def wrap(func):
        def wrapped(self, *args, **kwargs):
            if test():
                @unittest2.expectedFailure
                def f(): func(self)

                return f()
            return func(self)
        return wrapped
    return wrap 
Example #24
Source File: base.py    From blackmamba with MIT License 5 votes vote down vote up
def expectedFailurePY2(func):
    if not PY2:
        return func
    return unittest.expectedFailure(func)


# Renamed in Py3.3: 
Example #25
Source File: base.py    From blackmamba with MIT License 5 votes vote down vote up
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func) 
Example #26
Source File: base.py    From blackmamba with MIT License 5 votes vote down vote up
def expectedFailurePY26(func):
    if not PY26:
        return func
    return unittest.expectedFailure(func) 
Example #27
Source File: base.py    From blackmamba with MIT License 5 votes vote down vote up
def expectedFailurePY3(func):
    if not PY3:
        return func
    return unittest.expectedFailure(func) 
Example #28
Source File: support.py    From blackmamba with 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 #29
Source File: base.py    From addon with 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 #30
Source File: base.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def expectedFailurePY27(func):
    if not PY27:
        return func
    return unittest.expectedFailure(func)