mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add PYTHONWARNINGS=ignore option to silence deprecation warnings
This commit is contained in:
parent
2c72c0471b
commit
4d9eee7753
4 changed files with 20 additions and 2 deletions
1
changelog/64660.added.md
Normal file
1
changelog/64660.added.md
Normal file
|
@ -0,0 +1 @@
|
|||
Added ability to use PYTHONWARNINGS=ignore to silence deprecation warnings.
|
|
@ -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.
|
||||
|
|
|
@ -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,
|
||||
|
|
9
tests/pytests/functional/modules/test_test.py
Normal file
9
tests/pytests/functional/modules/test_test.py
Normal 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
|
Loading…
Add table
Reference in a new issue