Python unittest2 模块,skipIf() 实例源码

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

项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def testSecondInterrupt(self):
        # Can't use skipIf decorator because the signal handler may have
        # been changed after defining this method.
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest("test requires SIGINT to not be ignored")
        result = unittest2.TestResult()
        unittest2.installHandler()
        unittest2.registerResult(result)

        def test(result):
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
            result.breakCaught = True
            self.assertTrue(result.shouldStop)
            os.kill(pid, signal.SIGINT)
            self.fail("Second KeyboardInterrupt not raised")

        try:
            test(result)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("Second KeyboardInterrupt not raised")
        self.assertTrue(result.breakCaught)
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def testHandlerReplacedButCalled(self):
        # Can't use skipIf decorator because the signal handler may have
        # been changed after defining this method.
        if signal.getsignal(signal.SIGINT) == signal.SIG_IGN:
            self.skipTest("test requires SIGINT to not be ignored")
        # If our handler has been replaced (is no longer installed) but is
        # called by the *new* handler, then it isn't safe to delay the
        # SIGINT and we should immediately delegate to the default handler
        unittest2.installHandler()

        handler = signal.getsignal(signal.SIGINT)
        def new_handler(frame, signum):
            handler(frame, signum)
        signal.signal(signal.SIGINT, new_handler)

        try:
            pid = os.getpid()
            os.kill(pid, signal.SIGINT)
        except KeyboardInterrupt:
            pass
        else:
            self.fail("replaced but delegated handler doesn't raise interrupt")
项目:CSB    作者:csb-toolbox    | 项目源码 | 文件源码
def skip(reason, condition=None):
    """
    Mark a test case or method for skipping.

    @param reason: message
    @type reason: str
    @param condition: skip only if the specified condition is True
    @type condition: bool/expression
    """
    if isinstance(reason, types.FunctionType):
        raise TypeError('skip: no reason specified')

    if condition is None:
        return unittest.skip(reason)
    else:
        return unittest.skipIf(condition, reason)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:devsecops-example-helloworld    作者:boozallen    | 项目源码 | 文件源码
def test_skipping_decorators(self):
        op_table = ((unittest2.skipUnless, False, True),
                    (unittest2.skipIf, True, False))
        for deco, do_skip, dont_skip in op_table:
            class Foo(unittest2.TestCase):
                @deco(do_skip, "testing")
                def test_skip(self):
                    pass

                @deco(dont_skip, "testing")
                def test_dont_skip(self):
                    pass

            test_do_skip = Foo("test_skip")
            test_dont_skip = Foo("test_dont_skip")
            suite = unittest2.TestSuite([test_do_skip, test_dont_skip])
            events = []
            result = LoggingResult(events)
            suite.run(result)
            self.assertEqual(len(result.skipped), 1)
            expected = ['startTest', 'addSkip', 'stopTest',
                        'startTest', 'addSuccess', 'stopTest']
            self.assertEqual(events, expected)
            self.assertEqual(result.testsRun, 2)
            self.assertEqual(result.skipped, [(test_do_skip, "testing")])
            self.assertTrue(result.wasSuccessful())
项目:AshsSDK    作者:thehappydinoa    | 项目源码 | 文件源码
def skip_if_windows(reason):
    """Decorator to skip tests that should not be run on windows.

    Example usage:

        @skip_if_windows("Not valid")
        def test_some_non_windows_stuff(self):
            self.assertEqual(...)

    """
    def decorator(func):
        return unittest.skipIf(
            platform.system() not in ['Darwin', 'Linux'], reason)(func)
    return decorator
项目:Callandtext    作者:iaora    | 项目源码 | 文件源码
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
项目:My-Web-Server-Framework-With-Python2.7    作者:syjsu    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:annotated-py-tornado    作者:hhstore    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:Sudoku-Solver    作者:ayush1997    | 项目源码 | 文件源码
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
项目:teleport    作者:eomsoft    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:projects-2017-2    作者:ncss    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:enkiWS    作者:juliettef    | 项目源码 | 文件源码
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
项目:s3transfer    作者:boto    | 项目源码 | 文件源码
def skip_if_windows(reason):
    """Decorator to skip tests that should not be run on windows.

    Example usage:

        @skip_if_windows("Not valid")
        def test_some_non_windows_stuff(self):
            self.assertEqual(...)

    """
    def decorator(func):
        return unittest.skipIf(
            platform.system() not in ['Darwin', 'Linux'], reason)(func)
    return decorator
项目:s3transfer    作者:boto    | 项目源码 | 文件源码
def skip_if_using_serial_implementation(reason):
    """Decorator to skip tests when running as the serial implementation"""
    def decorator(func):
        return unittest.skipIf(
            is_serial_implementation(), reason)(func)
    return decorator
项目:python-flask-security    作者:weinbergdavid    | 项目源码 | 文件源码
def skipIf(condition, reason):
        if condition:
            return skip(reason)
        else:
            return lambda item: item
项目:BigBrotherBot-For-UrT43    作者:ptitbigorneau    | 项目源码 | 文件源码
def test_saybig_with_color_codes(self):
        self.parser.msgPrefix = "[Pre]"
        with patch.object(self.parser.output, 'write') as write_mock:
            self.parser.saybig("^7message ^1with ^2color ^8codes")
            write_mock.assert_has_calls([call('sm_hsay [Pre] message with color codes')])

#    @unittest.skipIf(WAS_FROSTBITE_LOADED, "Frostbite(1|2) parsers monkey patch the Client class and make this test fail")
项目:PyQYT    作者:collinsctk    | 项目源码 | 文件源码
def __getattr__(self, name):
        """Proxy all unknown attributes to the original method.

        This is important for some of the decorators in the `unittest`
        module, such as `unittest.skipIf`.
        """
        return getattr(self.orig_method, name)
项目:googleURLParser    作者:randomaccess3    | 项目源码 | 文件源码
def SkipIfCppImplementation(func):
  return unittest.skipIf(
      api_implementation.Type() == 'cpp' and api_implementation.Version() == 2,
      'C++ implementation does not expose unknown fields to Python')(func)
项目:OpenDoor    作者:stanislav-web    | 项目源码 | 文件源码
def test_total_lines(self):
        """ Reader.total_lines test """

        empty_reader = Reader(browser_config={})
        self.assertIs(type(empty_reader.total_lines), int)

    # def test_randomize_list_exception(self):
    #     """ Reader.randomize_list exception test """
    #
    #     reader = Reader(browser_config={})
    #     setattr(reader, '_Reader__config', self.__configuration_for_exception)
    #     setattr(sys, '_Output__is_windows', False)
    #     with self.assertRaises(ReaderError) as context:
    #         reader.randomize_list('directories', 'tmplist')
    #         self.assertTrue(ReaderError == context.expected)
    #
    # @unittest.skipIf(True is sys().is_windows, "Skip test for windows")
    # def test_randomize_list_unix(self):
    #     """ Reader.randomize_list unix test """
    #
    #     reader = Reader(browser_config={
    #         'is_external_wordlist': True,
    #         'list': 'tests/data/directories.dat',
    #     })
    #     setattr(reader, '_Reader__config', self.__configuration)
    #     reader.count_total_lines()
    #     self.assertIsNone(reader.randomize_list('directories', 'tmplist'))
    #     fe = open('tests/data/directories.dat', 'r')
    #     fa = open('tests/tmp/list.tmp', 'r')
    #     expected = sum(1 for l in fe)
    #     actual = sum(1 for l in fa)
    #     self.assertIs(expected, actual)
    #
    # def test_randomize_list_windows(self):
    #     """ Reader.randomize_list windows test """
    #
    #     reader = Reader(browser_config={
    #         'is_external_wordlist': True,
    #         'list': 'tests/data/directories.dat',
    #     })
    #     setattr(reader, '_Reader__config', self.__configuration)
    #     setattr(sys, 'is_windows', True)
    #     reader.count_total_lines()
    #     self.assertIsNone(reader.randomize_list('directories', 'tmplist'))
    #     fe = open('tests/data/directories.dat', 'r')
    #     fa = open('tests/tmp/list.tmp', 'r')
    #     expected = sum(1 for l in fe)
    #     actual = sum(1 for l in fa)
    #     self.assertIs(expected, actual)