diff --git a/dcos_test_utils/dcos_cli.py b/dcos_test_utils/dcos_cli.py index 3335bb2..0da47d1 100644 --- a/dcos_test_utils/dcos_cli.py +++ b/dcos_test_utils/dcos_cli.py @@ -101,8 +101,8 @@ def exec_command(self, cmd: str, stdin=None) -> tuple: :type cmd: str :param stdin: File to use for stdin :type stdin: File - :returns: A tuple with stdout and stderr - :rtype: (str, str) + :returns: A tuple with stdout, stderr and returncode + :rtype: (str, str, int) """ log.info('CMD: {!r}'.format(cmd)) @@ -126,7 +126,7 @@ def exec_command(self, cmd: str, stdin=None) -> tuple: log.info('STDOUT: {}'.format(stdout)) log.info('STDERR: {}'.format(stderr)) - return (stdout, stderr) + return (stdout, stderr, process.returncode) def setup_enterprise( self, diff --git a/tests/test_dcos_cli.py b/tests/test_dcos_cli.py index f6440b9..e851a21 100644 --- a/tests/test_dcos_cli.py +++ b/tests/test_dcos_cli.py @@ -6,7 +6,7 @@ def test_exec_command(caplog): cli = dcos_cli.DcosCli('') - stdout, stderr = cli.exec_command( + stdout, stderr, returncode = cli.exec_command( ['/bin/sh', '-c', 'echo "hello, world!"'] ) assert stdout == 'hello, world!\n' @@ -14,11 +14,14 @@ def test_exec_command(caplog): assert any(rec.message.startswith('CMD:') for rec in caplog.records) assert any(rec.message.startswith('STDOUT:') for rec in caplog.records) assert any(rec.message.startswith('STDERR:') for rec in caplog.records) + assert returncode == 0 def test_exec_command_fail(caplog): cli = dcos_cli.DcosCli('') with pytest.raises(subprocess.CalledProcessError): - cli.exec_command(['/bin/sh', '-c', 'does-not-exist']) + _stdout, _stderr, returncode = cli.exec_command(['/bin/sh', '-c', 'does-not-exist']) + assert returncode != 0 + assert any(rec.message.startswith('CMD:') for rec in caplog.records) assert any(rec.message.startswith('STDERR:') for rec in caplog.records)