Deprecate some test decorators

This commit is contained in:
Pedro Algarvio 2021-01-30 07:50:27 +00:00
parent e6914acf0e
commit ab1726fc6e

View file

@ -100,6 +100,12 @@ def destructiveTest(caller):
def test_create_user(self):
pass
"""
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@destructiveTest`, it will be removed in {date}, and instead use "
"`@pytest.mark.destructive_test`.",
stacklevel=3,
)
setattr(caller, "__destructive_test__", True)
if os.environ.get("DESTRUCTIVE_TESTS", "False").lower() == "false":
@ -132,6 +138,12 @@ def expensiveTest(caller):
def test_create_user(self):
pass
"""
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@expensiveTest`, it will be removed in {date}, and instead use "
"`@pytest.mark.expensive_test`.",
stacklevel=3,
)
setattr(caller, "__expensive_test__", True)
if os.environ.get("EXPENSIVE_TESTS", "False").lower() == "false":
@ -160,6 +172,12 @@ def slowTest(caller):
def test_that_takes_much_time(self):
pass
"""
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@slowTest`, it will be removed in {date}, and instead use "
"`@pytest.mark.slow_test`.",
stacklevel=3,
)
setattr(caller, "__slow_test__", True)
return caller
@ -552,6 +570,12 @@ def requires_network(only_local_network=False):
Simple decorator which is supposed to skip a test case in case there's no
network connection to the internet.
"""
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@requires_network`, it will be removed in {date}, and instead use "
"`@pytest.mark.requires_network`.",
stacklevel=3,
)
def decorator(func):
@functools.wraps(func)
@ -1144,6 +1168,12 @@ def requires_salt_states(*names):
.. versionadded:: 3000
"""
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@requires_salt_states`, it will be removed in {date}, and instead use "
"`@pytest.mark.requires_salt_states`.",
stacklevel=3,
)
not_available = _check_required_sminion_attributes("states", *names)
if not_available:
return skip("Unavailable salt states: {}".format(*not_available))
@ -1156,6 +1186,12 @@ def requires_salt_modules(*names):
.. versionadded:: 0.5.2
"""
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@requires_salt_modules`, it will be removed in {date}, and instead use "
"`@pytest.mark.requires_salt_modules`.",
stacklevel=3,
)
not_available = _check_required_sminion_attributes("functions", *names)
if not_available:
return skip("Unavailable salt modules: {}".format(*not_available))
@ -1163,6 +1199,12 @@ def requires_salt_modules(*names):
def skip_if_binaries_missing(*binaries, **kwargs):
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@skip_if_binaries_missing`, it will be removed in {date}, and instead use "
"`@pytest.mark.skip_if_binaries_missing`.",
stacklevel=3,
)
import salt.utils.path
if len(binaries) == 1:
@ -1193,6 +1235,12 @@ def skip_if_binaries_missing(*binaries, **kwargs):
def skip_if_not_root(func):
salt.utils.versions.warn_until_date(
"20220101",
"Please stop using `@skip_if_not_root`, it will be removed in {date}, and instead use "
"`@pytest.mark.skip_if_not_root`.",
stacklevel=3,
)
setattr(func, "__skip_if_not_root__", True)
if not sys.platform.startswith("win"):
@ -1332,6 +1380,7 @@ def generate_random_name(prefix, size=6):
"20220101",
"Please replace your call 'generate_random_name({0})' with 'random_string({0}, lowercase=False)' as "
"'generate_random_name' will be removed after {{date}}".format(prefix),
stacklevel=3,
)
return random_string(prefix, size=size, lowercase=False)