diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index 0ba6b3e..53f5ae2 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -50,7 +50,7 @@ jobs: TOX_PARALLEL_NO_SPINNER: 1 TOXENV: ${{ matrix.tox_env }} FORCE_COLOR: 1 - PYTEST_REQPASS: 24 + PYTEST_REQPASS: 25 steps: - name: Check vagrant presence diff --git a/src/vagrant/__init__.py b/src/vagrant/__init__.py index 1e3d0fd..ea880a4 100644 --- a/src/vagrant/__init__.py +++ b/src/vagrant/__init__.py @@ -1101,11 +1101,16 @@ def _run_vagrant_command(self, args) -> str: # Make subprocess command command = self._make_vagrant_command(args) with self.err_cm() as err_fh: - return compat.decode( - subprocess.check_output( + try: + output = subprocess.check_output( command, cwd=self.root, env=self.env, stderr=err_fh ) - ) + except subprocess.CalledProcessError as err: + output = err.output + log.error( + "Command %s returned with exit code %i", command, err.returncode + ) + return compat.decode(output) def _stream_vagrant_command(self, args) -> Iterator[str]: """ diff --git a/tests/test_vagrant.py b/tests/test_vagrant.py index f35d2b6..546c727 100644 --- a/tests/test_vagrant.py +++ b/tests/test_vagrant.py @@ -691,6 +691,18 @@ def test_ssh_command(vm_dir): assert output.strip() == "hello" +def test_bad_ssh_command(vm_dir, caplog): + """ + Test executing a failing command + """ + v = vagrant.Vagrant(vm_dir, quiet_stderr=False) + v.up() + v.ssh(command="logger -s oopsie; false") + assert "returned with exit code 1" in caplog.text + # https://github.com/pytest-dev/pytest/issues/5997 + # and capsys.readouterr().err == 'vagrant: oopsie' + + @pytest.mark.parametrize("vm_dir", (MULTIVM_VAGRANTFILE,), indirect=True) def test_ssh_command_multivm(vm_dir): """