From 29afcb22fd60dc7886c8590c235185bfaec6451a Mon Sep 17 00:00:00 2001 From: jonathan343 Date: Thu, 23 Jul 2026 02:10:25 -0400 Subject: [PATCH] Mock PermissionError in config file permission test 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. --- .../tests/unit/config/test_config_file_io.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/smithy-aws-core/tests/unit/config/test_config_file_io.py b/packages/smithy-aws-core/tests/unit/config/test_config_file_io.py index fe69a526c..a8db37c2c 100644 --- a/packages/smithy-aws-core/tests/unit/config/test_config_file_io.py +++ b/packages/smithy-aws-core/tests/unit/config/test_config_file_io.py @@ -3,6 +3,7 @@ from pathlib import Path +from unittest.mock import patch import pytest from smithy_aws_core.config import load_config @@ -26,12 +27,13 @@ async def test_load_config_with_missing_files(self, tmp_path: Path): async def test_permission_denied_returns_empty(self, tmp_path: Path): restricted_file = tmp_path / "restricted_config" restricted_file.write_text("[profile default]\nregion = us-east-1\n") - restricted_file.chmod(0o000) - try: + # Patch read_text to raise PermissionError rather than relying on + # chmod(0o000), which is bypassed when tests run as root (e.g. in CI). + with patch.object( + Path, "read_text", side_effect=PermissionError("Permission denied") + ): result = await parse_config_file(str(restricted_file)) - assert result == {} - finally: - restricted_file.chmod(0o644) + assert result == {} class TestEncodingErrors: