From 71218827449c6a2b24d650c8b06502009a928478 Mon Sep 17 00:00:00 2001 From: Megan Wilhite Date: Fri, 25 Aug 2023 21:15:44 -0600 Subject: [PATCH] Add additional deprecation warning tests --- tests/pytests/functional/modules/test_test.py | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/pytests/functional/modules/test_test.py b/tests/pytests/functional/modules/test_test.py index 7307822c0e1..84535a00b8d 100644 --- a/tests/pytests/functional/modules/test_test.py +++ b/tests/pytests/functional/modules/test_test.py @@ -1,9 +1,24 @@ -def test_deprecation_warnings_ignore(salt_call_cli): +import pytest + + +@pytest.mark.parametrize( + "env,warn_expected", + [ + ({"PYTHONWARNINGS": "ignore"}, False), + ({"PYTHONWARNINGS": "test"}, True), + ({}, True), + ], +) +def test_deprecation_warnings(salt_call_cli, env, warn_expected): """ Test to ensure when env variable PYTHONWARNINGS=ignore is set that we do not add warning to output. + And when it's not set to ignore the warning will show. """ - ret = salt_call_cli.run( - "--local", "test.deprecation_warning", env={"PYTHONWARNINGS": "ignore"} - ) - assert "DeprecationWarning" not in ret.stderr + ret = salt_call_cli.run("--local", "test.deprecation_warning", env=env) + if warn_expected: + assert "DeprecationWarning" in ret.stderr + assert ret.stderr.count("DeprecationWarning") >= 2 + else: + assert "DeprecationWarning" not in ret.stderr + assert ret.data