Open
Description
Hi,
I wrote a test like the following:
def test_salt_state_apply_test(host):
result = host.salt('state.apply', ['suse_ha', 'test=True'])
changed, changes = find_changes(result, True)
assert changed
The Salt command returns exit code 1 (or 2, with --retcode-passthrough
) - this is expected by me, and I further analyze the validity of the result using my custom logic (find_changes
, in this example).
However, Pytest does not execute my logic, as it immediately aborts the test after host.salt
returns:
def test_salt_state_apply_test(host):
> result = host.salt('state.apply', ['suse_ha', 'test=True'])
suse_ha-formula/tests/test_00_salt.py:40:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3.10/site-packages/testinfra/modules/salt.py:49: in __call__
return json.loads(self.check_output(cmd, *cmd_args))["local"]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
cls = <class 'testinfra.modules.base.Salt'>, args = ('salt-call --out=json %s %s %s', 'state.apply', 'suse_ha', 'test=True'), kwargs = {}
@classmethod
def check_output(cls, *args, **kwargs):
> return cls._host.check_output(*args, **kwargs)
< lots of output from Salt >
FAILED suse_ha-formula/tests/test_00_salt.py::test_salt_state_apply_test[paramiko://test-ha-minion-01] - AssertionError: Unexpected exit code 1 for CommandResult(command=b"sudo /bin/sh -c 'salt-call --out=json state.apply suse_ha test=True'", exit_status=1, stdout=b'{\n "local"...
Is there a way to ignore or whitelist "bad" exit codes and to continue my test function?
I only found run_expect
in the documentation, but would preferably continue using the Salt module.
It seems the issue is with check_output
having 0
defined as its only acceptable return code:
pytest-testinfra/testinfra/host.py
Line 116 in 8d69308
Metadata
Metadata
Assignees
Labels
No labels