From a7bf27b976f323a75a68efb95b7d9ea72ba27c82 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 7 Oct 2026 05:19:58 -0700 Subject: [PATCH] test: tolerate unset fixture variables in cleanup and cover DELETE ?logging Cleanup now runs its IAM/multipart steps only when setup reached them, so an early setup failure still removes the bucket. Added a DELETE bucket-subresource case asserting NotImplemented and bucket survival. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- test/s3/error_compat/s3_error_compat_test.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/s3/error_compat/s3_error_compat_test.py b/test/s3/error_compat/s3_error_compat_test.py index b8e31546b0..9d286eb54a 100644 --- a/test/s3/error_compat/s3_error_compat_test.py +++ b/test/s3/error_compat/s3_error_compat_test.py @@ -94,11 +94,17 @@ def S3(method, path, **kw): # ---------------- cleanup (atexit so failed runs still clean up) ---------------- +user = USER = upload_id = None + + def cleanup(): try: - send(**iam({'Action': 'DeleteAccessKey', 'UserName': user, 'AccessKeyId': USER.access_key})) - send(**iam({'Action': 'DeleteUser', 'UserName': user})) - send('DELETE', '/%s/mp?uploadId=%s' % (B, upload_id)) + if user and USER: + send(**iam({'Action': 'DeleteAccessKey', 'UserName': user, 'AccessKeyId': USER.access_key})) + if user: + send(**iam({'Action': 'DeleteUser', 'UserName': user})) + if upload_id: + send('DELETE', '/%s/mp?uploadId=%s' % (B, upload_id)) st, d = send('GET', '/%s?list-type=2' % B) for k in re.findall(r'([^<]+)', d): send('DELETE', '/%s/%s' % (B, urllib.parse.quote(k))) @@ -130,6 +136,9 @@ for sub in ('logging', 'notification', 'accelerate', 'website', 'replication', 'analytics&id=a', 'inventory&id=a', 'metrics&id=a', 'intelligent-tiering&id=a'): case(1, 'PUT ?%s' % sub, (501, 'Error', 'NotImplemented'), S3DOC + 'API_Error.html#:~:text=Code%3A%20NotImplemented', S3('PUT', '/%s?%s' % (B, sub), body=b'')) +case(1, 'DELETE ?logging', (501, 'Error', 'NotImplemented'), S3DOC + 'API_Error.html#:~:text=Code%3A%20NotImplemented', + S3('DELETE', '/%s?logging' % B), + lambda: 'bucket still exists' if send('HEAD', '/' + B)[0] == 200 else 'BUCKET DELETED') case(1, 'CopyObject, x-amz-copy-source without "/"', (400, 'Error', 'InvalidArgument'), S3DOC + 'API_CopyObject.html#AmazonS3-CopyObject-request-header-CopySource', S3('PUT', '/%s/copy-dst' % B, headers={'x-amz-copy-source': 'nobucketonly'}), exists('copy-dst'))