Add PYTHONWARNINGS=ignore option to silence deprecation warnings

This commit is contained in:
Megan Wilhite 2023-08-25 10:59:16 -06:00 committed by Pedro Algarvio
parent 2c72c0471b
commit 4d9eee7753
4 changed files with 20 additions and 2 deletions

1
changelog/64660.added.md Normal file
View file

@ -0,0 +1 @@
Added ability to use PYTHONWARNINGS=ignore to silence deprecation warnings.

View file

@ -55,3 +55,10 @@ Development begins on ``Aluminium``, or ``v3003``, after the ``v3002`` tag is
applied to the ``master`` branch. Once this occurs, all uses of the
``warn_until`` function targeting ``Aluminium``, along with the code they are
warning about should be removed from the code.
Silence Deprecation Warnings
----------------------------
If you set the `PYTHONWARNINGS` environment variable to `ignore` Salt will
not print the deprecation warnings.

View file

@ -12,6 +12,7 @@ import datetime
import inspect
import logging
import numbers
import os
import sys
import warnings
@ -183,7 +184,7 @@ def warn_until(
),
)
if _dont_call_warnings is False:
if _dont_call_warnings is False and os.environ.get("PYTHONWARNINGS") != "ignore":
warnings.warn(
message.format(version=version.formatted_version),
category,
@ -252,7 +253,7 @@ def warn_until_date(
),
)
if _dont_call_warnings is False:
if _dont_call_warnings is False and os.environ.get("PYTHONWARNINGS") != "ignore":
warnings.warn(
message.format(date=date.isoformat(), today=today.isoformat()),
category,

View file

@ -0,0 +1,9 @@
def test_deprecation_warnings_ignore(salt_call_cli):
"""
Test to ensure when env variable PYTHONWARNINGS=ignore
is set that we do not add warning to output.
"""
ret = salt_call_cli.run(
"--local", "test.deprecation_warning", env={"PYTHONWARNINGS": "ignore"}
)
assert "DeprecationWarning" not in ret.stderr