Add tests for deprecation warnings

Rather than just rely on the test suite, we also add a deprecation
warning to the test module, which will enable a simple method for
ensuring that DeprecationWarnings are correctly emitted.
This commit is contained in:
Wayne Werner 2022-12-19 23:14:34 -06:00 committed by Megan Wilhite
parent 3b06d1ed7c
commit 51f561065c
3 changed files with 34 additions and 0 deletions

1
changelog/63315.added Normal file
View file

@ -0,0 +1 @@
Added deprecation_warning test state for ensuring that deprecation warnings are correctly emitted.

View file

@ -16,6 +16,7 @@ import salt.utils.args
import salt.utils.functools
import salt.utils.hashutils
import salt.utils.platform
import salt.utils.versions
import salt.version
from salt.utils.decorators import depends
@ -675,3 +676,27 @@ def raise_exception(name, *args, **kwargs):
except AttributeError:
log.error("No such exception: %s", name)
return False
def deprecation_warning():
r"""
Return True, but also produce two DeprecationWarnings. One by date, the
other by the codename - release Oganesson, which should correspond to Salt
3108.
CLI Example:
.. code-block:: bash
salt \* test.deprecation_warning
"""
# This warn should always stay in Salt.
salt.utils.versions.warn_until(
"Oganesson",
"This is a test deprecation warning by version.",
)
salt.utils.versions.warn_until_date(
"30000101",
"This is a test deprecation warning by date very far into the future ({date}).",
)
return True

View file

@ -0,0 +1,8 @@
def test_deprecation_warning_emits_deprecation_warnings(salt_call_cli):
ret = salt_call_cli.run("test.deprecation_warning")
assert ret.stderr.count("DeprecationWarning") >= 2
assert "This is a test deprecation warning by version." in ret.stderr
assert (
"This is a test deprecation warning by date very far into the future (3000-01-01)"
in ret.stderr
)