本文整理汇总了Python中unittest.skipUnless方法的典型用法代码示例。如果您正苦于以下问题:Python unittest.skipUnless方法的具体用法?Python unittest.skipUnless怎么用?Python unittest.skipUnless使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest
的用法示例。
在下文中一共展示了unittest.skipUnless方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_skipping_decorators
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [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: test_ci_shippable
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def test_ci_shippable(self):
self.set_env(
SHIPPABLE="true",
BUILD_NUMBER="10",
REPO_NAME="owner/repo",
BRANCH="master",
BUILD_URL="https://shippable.com/...",
COMMIT="743b04806ea677403aa2ff26c6bdeb85005de658",
CODECOV_TOKEN="token",
CODECOV_NAME="name",
)
self.fake_report()
res = self.run_cli()
self.assertEqual(res["query"]["service"], "shippable")
self.assertEqual(
res["query"]["commit"], "743b04806ea677403aa2ff26c6bdeb85005de658"
)
self.assertEqual(res["query"]["build"], "10")
self.assertEqual(res["query"]["slug"], "owner/repo")
self.assertEqual(res["query"]["build_url"], "https://shippable.com/...")
self.assertEqual(res["codecov"].token, "token")
self.assertEqual(res["codecov"].name, "name")
# @unittest.skipUnless(os.getenv('CI') == "True" and os.getenv('APPVEYOR') == 'True', 'Skip AppVeyor CI test')
示例3: run_unittest
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def run_unittest(*classes):
"""Run tests from unittest.TestCase-derived classes."""
valid_types = (unittest.TestSuite, unittest.TestCase)
suite = unittest.TestSuite()
for cls in classes:
if isinstance(cls, str):
if cls in sys.modules:
suite.addTest(unittest.findTestCases(sys.modules[cls]))
else:
raise ValueError("str arguments must be keys in sys.modules")
elif isinstance(cls, valid_types):
suite.addTest(cls)
else:
suite.addTest(unittest.makeSuite(cls))
def case_pred(test):
if match_tests is None:
return True
for name in test.id().split("."):
if fnmatch.fnmatchcase(name, match_tests):
return True
return False
_filter_suite(suite, case_pred)
_run_suite(suite)
# We don't have sysconfig on Py2.6:
# #=======================================================================
# # Check for the presence of docstrings.
#
# HAVE_DOCSTRINGS = (check_impl_detail(cpython=False) or
# sys.platform == 'win32' or
# sysconfig.get_config_var('WITH_DOC_STRINGS'))
#
# requires_docstrings = unittest.skipUnless(HAVE_DOCSTRINGS,
# "test requires docstrings")
#
#
# #=======================================================================
# doctest driver.
示例4: live_only
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def live_only():
return unittest.skipUnless(
os.environ.get(ENV_LIVE_TEST, False),
'This is a live only test. A live test will bypass all vcrpy components.')
示例5: record_only
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def record_only():
return unittest.skipUnless(
not os.environ.get(ENV_LIVE_TEST, False),
'This test is excluded from being run live. To force a recording, please remove the recording file.')
示例6: setUpClass
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def setUpClass(cls):
cwd = os.path.dirname(os.path.realpath(__file__))
spec_dir = os.path.join(cwd, '../../openapi')
cls.swagger_path = os.path.join(spec_dir, 'data_repository_service.swagger.yaml')
cls.smartapi_path = os.path.join(spec_dir, 'data_repository_service.smartapi.yaml')
cls.openapi_path = os.path.join(spec_dir, 'data_repository_service.openapi.yaml')
# The :func:`unittest.skipUnless` calls depend on class variables,
# which means that we can't decorate the test cases conventionally
# and have to do so after the class variables we need are instantiated.
openapi_dec = unittest.skipUnless(os.path.exists(cls.openapi_path), "Generated schema not found.")
cls.test_openapi_schema_validity = openapi_dec(cls.test_openapi_schema_validity)
smartapi_dec = unittest.skipUnless(os.path.exists(cls.smartapi_path), "Generated schema not found.")
cls.test_smartapi_schema_validity = smartapi_dec(cls.test_smartapi_schema_validity)
示例7: with_docker_executor
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def with_docker_executor(wrapped=None):
"""Decorate unit test to run processes with the Docker executor."""
if wrapped is None:
return functools.partial(with_docker_executor)
@wrapt.decorator
def wrapper(wrapped_method, instance, args, kwargs):
return unittest.skipUnless(*check_docker())(
with_custom_executor(NAME="resolwe.flow.executors.docker",)(wrapped_method)
)(*args, **kwargs)
return wrapper(wrapped)
示例8: skipUnlessIronPython
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def skipUnlessIronPython():
"""Skips the test unless currently running on IronPython"""
return unittest.skipUnless(is_cli, 'IronPython specific test')
示例9: need_symbol
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def need_symbol(name):
return unittest.skipUnless(name in ctypes_symbols,
'{!r} is required'.format(name))
示例10: _make_tarball
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def _make_tarball(self, target_name):
# creating something to tar
tmpdir = self.mkdtemp()
self.write_file([tmpdir, 'file1'], 'xxx')
self.write_file([tmpdir, 'file2'], 'xxx')
os.mkdir(os.path.join(tmpdir, 'sub'))
self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
tmpdir2 = self.mkdtemp()
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
"source and target should be on same drive")
base_name = os.path.join(tmpdir2, target_name)
# working with relative paths to avoid tar warnings
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
make_tarball(splitdrive(base_name)[1], '.')
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
self.assertTrue(os.path.exists(tarball))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, target_name)
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
make_tarball(splitdrive(base_name)[1], '.', compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
示例11: test_unicode
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def test_unicode(self):
if not test_support.have_unicode:
# Python 2.5 has no unittest.skipUnless
self.skipTest('no unicode support')
endcases = [u'', u'<\\u>', u'<\\%c>' % 0x1234, u'<\n>', u'<\\>']
for proto in pickletester.protocols:
for u in endcases:
p = self.dumps(u, proto)
u2 = self.loads(p)
self.assertEqual(u2, u)
# The ability to pickle recursive objects was added in 2.7.11 to fix
# a crash in CPickle (issue #892902).
示例12: test_make_tarball
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def test_make_tarball(self):
# creating something to tar
tmpdir = self.mkdtemp()
self.write_file([tmpdir, 'file1'], 'xxx')
self.write_file([tmpdir, 'file2'], 'xxx')
os.mkdir(os.path.join(tmpdir, 'sub'))
self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
tmpdir2 = self.mkdtemp()
# force shutil to create the directory
os.rmdir(tmpdir2)
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
"source and target should be on same drive")
base_name = os.path.join(tmpdir2, 'archive')
# working with relative paths to avoid tar warnings
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(splitdrive(base_name)[1], '.')
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
self.assertTrue(os.path.exists(tarball))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive')
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
_make_tarball(splitdrive(base_name)[1], '.', compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
示例13: test_make_tarball
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def test_make_tarball(self):
# creating something to tar
tmpdir = self.mkdtemp()
self.write_file([tmpdir, 'file1'], 'xxx')
self.write_file([tmpdir, 'file2'], 'xxx')
os.mkdir(os.path.join(tmpdir, 'sub'))
self.write_file([tmpdir, 'sub', 'file3'], 'xxx')
tmpdir2 = self.mkdtemp()
unittest.skipUnless(splitdrive(tmpdir)[0] == splitdrive(tmpdir2)[0],
"source and target should be on same drive")
base_name = os.path.join(tmpdir2, 'archive')
# working with relative paths to avoid tar warnings
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
make_tarball(splitdrive(base_name)[1], '.')
finally:
os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
self.assertTrue(os.path.exists(tarball))
# trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive')
old_dir = os.getcwd()
os.chdir(tmpdir)
try:
make_tarball(splitdrive(base_name)[1], '.', compress=None)
finally:
os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
示例14: requires_tcl
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def requires_tcl(*version):
return unittest.skipUnless(tcl_version >= version,
'requires Tcl version >= ' + '.'.join(map(str, version)))
示例15: skipUnlessDom0
# 需要导入模块: import unittest [as 别名]
# 或者: from unittest import skipUnless [as 别名]
def skipUnlessDom0(test_item):
"""Decorator that skips test outside dom0.
Some tests (especially integration tests) have to be run in more or less
working dom0. This is checked by connecting to libvirt.
"""
return unittest.skipUnless(in_dom0, 'outside dom0')(test_item)