Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Ignore Salt exit codes

Đang mở
#705 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python

Hướng nghiên cứu

Start by reading testinfra/modules/salt.py around the Salt module call and host.py at the referenced check_output implementation. Check the existing run_expect documentation for related behavior, then determine how accepted exit codes should be represented so Salt results can be analyzed; done means the reported valid codes no longer abort the test and coverage verifies the behavior.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

https://github.com/pytest-dev/pytest-testinfra/blob/8d693089eac355948cb72d89c607400fcac783da/testinfra/host.py#L116

Ngôn ngữ chính
Python
Star
2.5k
Fork
360
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pytest-dev/pytest-testinfra

Tất cả issue của pytest-dev/pytest-testinfra

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.