From 14a932aca4c1b7faf34decc5d5ca2861924c84c9 Mon Sep 17 00:00:00 2001 From: jeanluc Date: Tue, 22 Mar 2022 13:19:10 +0100 Subject: [PATCH] Fix tests for real this time --- tests/pytests/unit/modules/test_cmdmod.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/pytests/unit/modules/test_cmdmod.py b/tests/pytests/unit/modules/test_cmdmod.py index b201a8722ec9..619a92702a61 100644 --- a/tests/pytests/unit/modules/test_cmdmod.py +++ b/tests/pytests/unit/modules/test_cmdmod.py @@ -489,14 +489,22 @@ def mock_proc(__cmd__, **kwargs): ), "cmd does not invoke user shell on macOS" +@pytest.mark.skip_on_windows def test_run_all_quiet_does_not_depend_on_salt_dunder(): """ - cmdmod._run_all_quiet should not depend on availability - of __salt__ dictionary (issue #61816) + `cmdmod._run_all_quiet` should not depend on availability + of __salt__ dictionary (issue #61816). + + This test checks for __salt__ specifically and will still + pass if other dunders, especially __grains__, are referenced. + This is the case on UNIX systems other than MacOS when + `sudo` could not be found. """ proc = MagicMock(return_value=MockTimedProc(stdout=b"success", stderr=None)) - with patch("pwd.getpwnam") as getpwnam_mock: + runas = getpass.getuser() + + with patch.dict(cmdmod.__grains__, {"os": "Darwin", "os_family": "Solaris"}): with patch("salt.utils.timed_subprocess.TimedProc", proc): salt_dunder_mock = MagicMock(spec_set=dict) salt_dunder_mock.__getitem__.side_effect = NameError( @@ -507,7 +515,7 @@ def test_run_all_quiet_does_not_depend_on_salt_dunder(): ret = cmdmod._run_all_quiet("foo") assert ret["stdout"] == "success" assert salt_dunder_mock.__getitem__.call_count == 0 - ret = cmdmod._run_all_quiet("foo", runas="bar") + ret = cmdmod._run_all_quiet("foo", runas=runas) assert ret["stdout"] == "success" assert salt_dunder_mock.__getitem__.call_count == 0