当前位置: 首页>>代码示例>>Python>>正文


Python unittest.skipIf方法代码示例

本文整理汇总了Python中unittest.skipIf方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.skipIf方法的具体用法?Python unittest.skipIf怎么用?Python unittest.skipIf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在unittest的用法示例。


在下文中一共展示了unittest.skipIf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_skipping_decorators

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def test_skipping_decorators(self):
        op_table = ((unittest.skipUnless, False, True),
                    (unittest.skipIf, True, False))
        for deco, do_skip, dont_skip in op_table:
            class Foo(unittest.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 = unittest.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()) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:25,代码来源:test_skipping.py

示例2: testSecondInterrupt

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
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 = unittest.TestResult()
        unittest.installHandler()
        unittest.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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_break.py

示例3: testHandlerReplacedButCalled

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
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
        unittest.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") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_break.py

示例4: multi_gpu

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def multi_gpu(gpu_num):
    """Decorator to indicate number of GPUs required to run the test.

    Tests can be annotated with this decorator (e.g., ``@multi_gpu(2)``) to
    declare number of GPUs required to run. When running tests, if
    ``CHAINER_TEST_GPU_LIMIT`` environment variable is set to value greater
    than or equals to 0, test cases that require GPUs more than the limit will
    be skipped.
    """

    check_available()

    def deco(f):
        return unittest.skipIf(
            0 <= _gpu_limit < gpu_num,
            reason='{} GPUs required'.format(gpu_num)
        )(pytest.mark.gpu(f))

    return deco 
开发者ID:chainer,项目名称:chainer,代码行数:21,代码来源:attr.py

示例5: test_pdb_unittest_skip

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def test_pdb_unittest_skip(self, testdir):
        """Test for issue #2137"""
        p1 = testdir.makepyfile(
            """
            import unittest
            @unittest.skipIf(True, 'Skipping also with pdb active')
            class MyTestCase(unittest.TestCase):
                def test_one(self):
                    assert 0
        """
        )
        child = testdir.spawn_pytest("-rs --pdb %s" % p1)
        child.expect("Skipping also with pdb active")
        child.expect_exact("= 1 skipped in")
        child.sendeof()
        self.flush(child) 
开发者ID:pytest-dev,项目名称:pytest,代码行数:18,代码来源:test_debugging.py

示例6: test_compute_rollover_daily_attime

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def test_compute_rollover_daily_attime(self):
        currentTime = 0
        atTime = datetime.time(12, 0, 0)
        rh = logging.handlers.TimedRotatingFileHandler(
            self.fn, when='MIDNIGHT', interval=1, backupCount=0, utc=True,
            atTime=atTime)
        try:
            actual = rh.computeRollover(currentTime)
            self.assertEqual(actual, currentTime + 12 * 60 * 60)

            actual = rh.computeRollover(currentTime + 13 * 60 * 60)
            self.assertEqual(actual, currentTime + 36 * 60 * 60)
        finally:
            rh.close()

    #@unittest.skipIf(True, 'Temporarily skipped while failures investigated.') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:18,代码来源:test_logging.py

示例7: skipIfNoExec

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def skipIfNoExec(cmd):
    return unittest.skipIf(shutil.which(cmd) is None, f'`{cmd}` is not available') 
开发者ID:pytorch,项目名称:audio,代码行数:4,代码来源:test_case_utils.py

示例8: skipIfNoModule

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def skipIfNoModule(module, display_name=None):
    display_name = display_name or module
    return unittest.skipIf(not is_module_available(module), f'"{display_name}" is not available') 
开发者ID:pytorch,项目名称:audio,代码行数:5,代码来源:test_case_utils.py

示例9: setUpClass

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def setUpClass(self):
        from pyspider.message_queue import connect_message_queue
        with utils.timeout(3):
            self.q1 = self.q2 = connect_message_queue('test_queue', maxsize=5)
            self.q3 = connect_message_queue('test_queue_for_threading_test')


#@unittest.skipIf(six.PY3, 'pika not suport python 3') 
开发者ID:binux,项目名称:pyspider,代码行数:10,代码来源:test_message_queue.py

示例10: needs_cvxpy

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def needs_cvxpy(fn):
    """Shortcut decorator for skipping tests that require CVXPY"""
    return unittest.skipIf('SKIP_CVXPY' in os.environ, "skipping cvxpy tests")(fn) 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:5,代码来源:util.py

示例11: needs_deap

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def needs_deap(fn):
    """Shortcut decorator for skipping tests that require deap"""
    return unittest.skipIf('SKIP_DEAP' in os.environ, "skipping deap tests")(fn) 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:5,代码来源:util.py

示例12: needs_matplotlib

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def needs_matplotlib(fn):
    """Shortcut decorator for skipping tests that require matplotlib"""
    return unittest.skipIf('SKIP_MATPLOTLIB' in os.environ, "skipping matplotlib tests")(fn) 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:5,代码来源:util.py

示例13: __getattr__

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:testing.py

示例14: require_backend

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def require_backend(backend):
    return unittest.skipIf(backend not in VALID_EC_TYPES,
                           "%s backend is not available" % backend) 
开发者ID:openstack,项目名称:pyeclib,代码行数:5,代码来源:test_pyeclib_c.py

示例15: notquick

# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipIf [as 别名]
def notquick(arg):
    @wraps(arg)
    def _not_quick(arg):
        return unittest.skipIf(os.getenv("QUICK_TESTS_ONLY"), "Ignored slow test.")(arg)

    return _not_quick(arg) 
开发者ID:johnbywater,项目名称:eventsourcing,代码行数:8,代码来源:base.py


注:本文中的unittest.skipIf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。