Inline our code with what unittest.case.skip does

This commit is contained in:
Wayne Werner 2020-05-05 09:23:04 -05:00 committed by Daniel Wozniak
parent ca4e3c5e93
commit 1e16375702

View file

@ -175,11 +175,8 @@ def expensiveTest(caller):
def slowTest(caller):
"""
Mark a test case as a slow test.
.. code-block:: python
class MyTestCase(TestCase):
@slowTest
def test_that_takes_much_time(self):
pass
@ -190,14 +187,20 @@ def slowTest(caller):
if RUNTIME_VARS.PYTEST_SESSION:
setattr(caller, "__slow_test__", True)
# We're simply decorating functions
@functools.wraps(caller)
def wrap(cls, *args, **kwargs):
if os.environ.get("SLOW_TESTS", "False").lower() == "false":
raise SkipTest("Slow tests are disabled")
return caller(cls, *args, **kwargs)
if os.environ.get("SLOW_TESTS", "False").lower() == "false":
reason = "Slow tests are disabled"
return wrap
if not isinstance(caller, type):
@functools.wraps(caller)
def skip_wrapper(*args, **kwargs):
raise SkipTest(reason)
caller = skip_wrapper
caller.__unittest_skip__ = True
caller.__unittest_skip_why__ = reason
return caller
def flaky(caller=None, condition=True, attempts=4):