Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put back deprecation warnings #63315

Merged
merged 8 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/62185.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restored Salt's DeprecationWarnings
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.
3 changes: 2 additions & 1 deletion salt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def load_module(self, name):
"", # No deprecation message match
DeprecationWarning, # This filter is for DeprecationWarnings
r"^(salt|salt\.(.*))$", # Match module(s) 'salt' and 'salt.<whatever>'
append=True,
# Do *NOT* add append=True here - if we do, salt's DeprecationWarnings will
# never show up
)

# Filter the backports package UserWarning about being re-imported
Expand Down
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
)