diff --git a/changelog/63315.added b/changelog/63315.added new file mode 100644 index 000000000000..950abc93277b --- /dev/null +++ b/changelog/63315.added @@ -0,0 +1 @@ +Added deprecation_warning test state for ensuring that deprecation warnings are correctly emitted. diff --git a/salt/modules/test.py b/salt/modules/test.py index fc710255f34b..62d96f52118b 100644 --- a/salt/modules/test.py +++ b/salt/modules/test.py @@ -16,6 +16,7 @@ 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 _is_exc(cls): 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 diff --git a/tests/pytests/integration/modules/test_test.py b/tests/pytests/integration/modules/test_test.py new file mode 100644 index 000000000000..82f6432383be --- /dev/null +++ b/tests/pytests/integration/modules/test_test.py @@ -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 + )