Skip to content

Mock PermissionError in config file permission test#750

Merged
jonathan343 merged 1 commit into
developfrom
fix-file-permissions-test
Jul 23, 2026
Merged

Mock PermissionError in config file permission test#750
jonathan343 merged 1 commit into
developfrom
fix-file-permissions-test

Conversation

@jonathan343

@jonathan343 jonathan343 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix test_permission_denied_returns_empty failing in release infra by mocking the PermissionError instead of relying on filesystem permission bits.

Issue

The test used chmod(0o000) to make a config file unreadable, expecting parse_config_file to catch a PermissionError and return {}. This passed locally but failed in release infra because CI runs tests as root, which bypasses Unix permission bits. The read succeeded, the file was parsed, and the result was {'profile default': {'region': 'us-east-1'}} instead of {}.

Solution

Replace the chmod with patch.object(Path, "read_text", side_effect=PermissionError(...)). This deterministically exercises the except (PermissionError, OSError) branch regardless of the running user, and matches the mocking approach already used in test_config_file_location.py.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

chmod(0o000) is bypassed when tests run as root (e.g. in CI), so the
file was still readable and the test failed. Patch Path.read_text to
raise PermissionError instead, exercising the error-handling branch
deterministically regardless of user.
@jonathan343
jonathan343 requested a review from a team as a code owner July 23, 2026 06:20
@jonathan343
jonathan343 merged commit 5c01bb7 into develop Jul 23, 2026
10 checks passed
@jonathan343
jonathan343 deleted the fix-file-permissions-test branch July 23, 2026 14:39
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