diff --git a/test/unittests/test_sh.py b/test/unittests/test_sh.py index b3c0f0bb11..221820afd2 100644 --- a/test/unittests/test_sh.py +++ b/test/unittests/test_sh.py @@ -13,8 +13,9 @@ def setUp(self) -> None: self.local_shell.geteuid = mock.Mock(self.local_shell.geteuid) self.local_shell.hostname = mock.Mock(self.local_shell.hostname) + @mock.patch('os.environ') @mock.patch('subprocess.run') - def test_su_subprocess_run(self, mock_run: mock.MagicMock): + def test_su_subprocess_run(self, mock_run: mock.MagicMock, mock_environ: mock.MagicMock): self.local_shell.get_effective_user_name.return_value = 'root' self.local_shell.geteuid.return_value = 0 self.local_shell.su_subprocess_run( @@ -24,10 +25,12 @@ def test_su_subprocess_run(self, mock_run: mock.MagicMock): mock_run.assert_called_once_with( ['su', 'alice', '--login', '-s', '/bin/sh', '-c', 'foo'], input=b'bar', + env=mock_environ, ) + @mock.patch('os.environ') @mock.patch('subprocess.run') - def test_su_subprocess_run_as_root(self, mock_run: mock.MagicMock): + def test_su_subprocess_run_as_root(self, mock_run: mock.MagicMock, mock_environ: mock.MagicMock): self.local_shell.get_effective_user_name.return_value = 'root' self.local_shell.geteuid.return_value = 0 self.local_shell.su_subprocess_run( @@ -37,6 +40,7 @@ def test_su_subprocess_run_as_root(self, mock_run: mock.MagicMock): mock_run.assert_called_once_with( ['/bin/sh', '-c', 'foo'], input=b'bar', + env=mock_environ, ) @mock.patch('subprocess.run') @@ -124,8 +128,9 @@ def test_subprocess_run_without_input_with_input_kwargs(self): ) self.ssh_shell.local_shell.su_subprocess_run.assert_not_called() + @mock.patch('os.environ') @mock.patch('subprocess.run') - def test_subprocess_run_without_input_local(self, mock_run): + def test_subprocess_run_without_input_local(self, mock_run, mock_environ: mock.MagicMock): self.ssh_shell.subprocess_run_without_input( 'node1', 'bob', 'foo', @@ -138,6 +143,7 @@ def test_subprocess_run_without_input_local(self, mock_run): input=b'foo', stdout=subprocess.PIPE, stderr=subprocess.PIPE, + env=mock_environ, )