Skip to content

Commit

Permalink
Fix tests for real this time
Browse files Browse the repository at this point in the history
  • Loading branch information
lkubb authored and Megan Wilhite committed Sep 7, 2022
1 parent 25b6c1d commit 14a932a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tests/pytests/unit/modules/test_cmdmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand Down

0 comments on commit 14a932a

Please sign in to comment.