Python unittest.skipUnless() Examples
The following are 30
code examples of unittest.skipUnless().
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
unittest
, or try the search function
.
Example #1
Source File: test_skipping.py From jawfish with MIT License | 6 votes |
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())
Example #2
Source File: test_skipping.py From datafari with Apache License 2.0 | 6 votes |
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())
Example #3
Source File: test_skipping.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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())
Example #4
Source File: test_skipping.py From oss-ftp with MIT License | 6 votes |
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())
Example #5
Source File: test.py From codecov-python with Apache License 2.0 | 6 votes |
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')
Example #6
Source File: test_skipping.py From BinderFilter with MIT License | 6 votes |
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())
Example #7
Source File: test_skipping.py From Imogen with MIT License | 6 votes |
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())
Example #8
Source File: test_skipping.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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())
Example #9
Source File: test_skipping.py From ironpython2 with Apache License 2.0 | 6 votes |
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())
Example #10
Source File: test_skipping.py From ironpython3 with Apache License 2.0 | 6 votes |
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())
Example #11
Source File: test_skipping.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
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())
Example #12
Source File: __init__.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def need_symbol(name): return unittest.skipUnless(name in ctypes_symbols, '{!r} is required'.format(name))
Example #13
Source File: test_examples.py From daal4py with Apache License 2.0 | 5 votes |
def add_test(cls, e, f=None, attr=None, ver=(0,0)): import importlib @unittest.skipUnless(check_version(ver, daal_version), "not supported in this library version") def testit(self): ex = importlib.import_module(e) result = self.call(ex) if f and attr: testdata = np_read_csv(os.path.join(unittest_data_path, f)) actual = attr(result) if callable(attr) else getattr(result, attr) self.assertTrue(np.allclose(actual, testdata, atol=1e-05), msg="Discrepancy found: {}".format(np.abs(actual-testdata).max())) else: self.assertTrue(True) setattr(cls, 'test_'+e, testit)
Example #14
Source File: test.py From texar-pytorch with Apache License 2.0 | 5 votes |
def define_skip_condition(flag: str, explanation: str): return unittest.skipUnless( os.environ.get(flag, 0) or os.environ.get('TEST_ALL', 0), explanation + f" Set `{flag}=1` or `TEST_ALL=1` to run.")
Example #15
Source File: test_archive_util.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def _make_tarball(self, tmpdir, target_name, suffix, **kwargs): 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 with change_cwd(tmpdir): make_tarball(splitdrive(base_name)[1], 'dist', **kwargs) # check if the compressed tarball was created tarball = base_name + suffix self.assertTrue(os.path.exists(tarball)) self.assertEqual(self._tarinfo(tarball), self._created_files)
Example #16
Source File: test_passwords.py From btcrecover with GNU General Public License v2.0 | 5 votes |
def skipUnless(condition_func, reason): assert callable(condition_func) def decorator(test_func): def skip_or_test(self): if not condition_func(): self.skipTest(reason) test_func(self) return skip_or_test return decorator
Example #17
Source File: utils.py From scuba with MIT License | 5 votes |
def skipUnlessTty(): return unittest.skipUnless(sys.stdin.isatty(), "Can't test docker tty if not connected to a terminal")
Example #18
Source File: testing_utils.py From neural_chat with MIT License | 5 votes |
def skipUnlessGPU(testfn, reason='Test requires a GPU'): """Decorate a test to skip if no GPU is available.""" return unittest.skipUnless(GPU_AVAILABLE, reason)(testfn)
Example #19
Source File: testing_utils.py From KBRD with MIT License | 5 votes |
def skipUnlessGPU(testfn, reason='Test requires a GPU'): """Decorator for skipping a test if no GPU is available.""" return unittest.skipUnless(GPU_AVAILABLE, reason)(testfn)
Example #20
Source File: test_utils.py From sdc with BSD 2-Clause "Simplified" License | 5 votes |
def skip_numba_jit(msg_or_func=None): msg, func = msg_and_func(msg_or_func) wrapper = unittest.skipUnless(sdc.config.config_pipeline_hpat_default, msg or "numba pipeline not supported") if sdc.config.test_expected_failure: wrapper = unittest.expectedFailure # wrapper = lambda f: f # disable skipping return wrapper(func) if func else wrapper
Example #21
Source File: testing_utils.py From KBRD with MIT License | 5 votes |
def skipUnlessTorch(testfn, reason='pytorch is not installed'): """Decorator for skipping a test if torch is not installed.""" return unittest.skipUnless(TORCH_AVAILABLE, reason)(testfn)
Example #22
Source File: skip.py From seldom with Apache License 2.0 | 5 votes |
def skip_unless(condition, reason): """ Skip a test unless the condition is true. :param condition: :param reason: :return: """ return unittest.skipUnless(condition, reason)
Example #23
Source File: support.py From addon with GNU General Public License v3.0 | 5 votes |
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.
Example #24
Source File: support.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
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.
Example #25
Source File: attr.py From chainercv with MIT License | 5 votes |
def mpi(f): check_available() import pytest try: import mpi4py.MPI # NOQA available = True except ImportError: available = False return unittest.skipUnless( available, 'mpi4py is not installed')(pytest.mark.mpi(f))
Example #26
Source File: test_time.py From ironpython3 with Apache License 2.0 | 5 votes |
def skip_if_not_supported(y): msg = "strftime() is limited to [1; 9999] with Visual Studio" # Check that it doesn't crash for year > 9999 try: time.strftime('%Y', (y,) + (0,) * 8) except ValueError: cond = False else: cond = True return unittest.skipUnless(cond, msg)
Example #27
Source File: test_archive_util.py From ironpython3 with Apache License 2.0 | 5 votes |
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))
Example #28
Source File: __init__.py From ironpython3 with Apache License 2.0 | 5 votes |
def need_symbol(name): return unittest.skipUnless(name in ctypes_symbols, '{!r} is required'.format(name))
Example #29
Source File: ipunittest.py From ironpython3 with Apache License 2.0 | 5 votes |
def skipUnlessIronPython(): """Skips the test unless currently running on IronPython""" return unittest.skipUnless(is_cli, 'IronPython specific test')
Example #30
Source File: support.py From verge3d-blender-addon with GNU General Public License v3.0 | 5 votes |
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.