本文整理汇总了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())
示例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)
示例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")
示例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
示例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)
示例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.')
示例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')
示例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')
示例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')
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)