Fix unit.modules.test_cmdmod.CMDMODTestCase.test_run

The test_run unit tests end result when a command is not found. When
_run() is called without setting cwd, it will use the home directory as
working directory. When the home directory does not exist, the unit test
will fail:

Traceback (most recent call last):
  File "tests/unit/modules/test_cmdmod.py", line 231, in test_run
    ret = cmdmod._run('foo', use_vt=True).get('stderr')
  File "salt/modules/cmdmod.py", line 536, in _run
    .format(cwd)
salt.exceptions.CommandExecutionError: Specified cwd
'/sbuild-nonexistent' either not absolute or does not exist

Therefore set cwd to the current directory since the working directory
is not used in this test case.

This fixes one failing test of #45627.

Signed-off-by: Benjamin Drung <benjamin.drung@profitbricks.com>
This commit is contained in:
Benjamin Drung 2018-01-23 13:13:46 +01:00
parent 63a294f498
commit 2b9b262357

View file

@ -228,7 +228,7 @@ class CMDMODTestCase(TestCase, LoaderModuleMockMixin):
with patch('salt.utils.is_windows', MagicMock(return_value=False)):
with patch('os.path.isfile', MagicMock(return_value=True)):
with patch('os.access', MagicMock(return_value=True)):
ret = cmdmod._run('foo', use_vt=True).get('stderr')
ret = cmdmod._run('foo', cwd=os.getcwd(), use_vt=True).get('stderr')
self.assertIn('foo', ret)
def test_is_valid_shell_windows(self):