From 0b9036223331a8c382e64b18569ee8702ed9fe9f Mon Sep 17 00:00:00 2001 From: Danny Hermes Date: Thu, 22 Jan 2015 11:58:48 -0800 Subject: [PATCH] Making sure delete does not fail in regression tests. Fixes #531. See #535 for context. --- regression/storage.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/regression/storage.py b/regression/storage.py index 0fbcd7c1d52b..fe07a096353a 100644 --- a/regression/storage.py +++ b/regression/storage.py @@ -39,10 +39,20 @@ def setUpModule(): SHARED_BUCKETS['test_bucket'] = connection.create_bucket(bucket_name) +def safe_delete(bucket): + for key in bucket: + try: + key.delete() + except storage.exceptions.NotFound: + print('Delete failed with 404: %r' % (key,)) + + # Passing force=False does not try to delete the contained files. + bucket.delete(force=False) + + def tearDownModule(): for bucket in SHARED_BUCKETS.values(): - # Passing force=True also deletes all files. - bucket.delete(force=True) + safe_delete(bucket) class TestStorage(unittest2.TestCase):