Skip to content

fix: handle ansible encoding errors and update rocky9 package assertion#820

Merged
philpep merged 1 commit into
pytest-dev:mainfrom
shenxianpeng:bugfix/fix-ci-encoding-and-package-version
Jun 2, 2026
Merged

fix: handle ansible encoding errors and update rocky9 package assertion#820
philpep merged 1 commit into
pytest-dev:mainfrom
shenxianpeng:bugfix/fix-ci-encoding-and-package-version

Conversation

@shenxianpeng
Copy link
Copy Markdown
Contributor

Summary

Fixes CI failures in the build (py311) job:

1. Handle Ansible encoding errors gracefully (testinfra/backend/ansible.py)

When Ansible fails to run a command (e.g., due to UTF-8 surrogate encoding issues), it returns a response with only a msg key and no stdout/stderr. Previously this caused a KeyError: 'stdout'. Now the code:

  • Checks for module_stdout (new ansible format)
  • Falls back to stdout (backward compat)
  • Falls back to msg for error responses, placed in stderr
  • Uses .get("rc", 1) since rc may also be missing

2. Make encoding test resilient to Ansible version differences (test/test_backends.py)

The test_encoding[ansible://debian_bookworm?force_ansible=True] test now accepts either the old-style ls error message with surrogates (older ansible) or the new surrogate-rejection transport error from newer ansible versions. Also asserts cmd.failed is True.

3. Update Rocky Linux 9 package version expectation (test/test_modules.py)

The rocky linux 9 docker image now ships openssh-server 9.9p1 instead of 8.x. Updated version prefix from "8." to "9.".


Fixes CI run: https://github.com/pytest-dev/pytest-testinfra/actions/runs/26749425227

- ansible.py: handle ansible error responses containing only 'msg' key
  (no stdout/stderr) to avoid KeyError when commands fail at transport
  layer due to encoding issues
- test_backends.py: update encoding test to accept both old-style ansible
  error messages and new surrogate-rejection errors from newer ansible
- test_modules.py: update rocky linux 9 openssh-server version prefix
  from 8. to 9. (new image ships openssh-server 9.9p1)
@philpep philpep merged commit a9b8504 into pytest-dev:main Jun 2, 2026
9 checks passed
@philpep
Copy link
Copy Markdown
Contributor

philpep commented Jun 2, 2026

Merged, thanks!

@shenxianpeng shenxianpeng deleted the bugfix/fix-ci-encoding-and-package-version branch June 2, 2026 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants