Skip to content

Commit

Permalink
Add tests for deprecation warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
waynew authored and s0undt3ch committed Dec 20, 2022
1 parent 25d6780 commit 9c896fe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/63315.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added deprecation_warning test state for ensuring that deprecation warnings are correctly emitted.
25 changes: 25 additions & 0 deletions salt/modules/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions tests/pytests/integration/modules/test_test.py
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit 9c896fe

Please sign in to comment.