@@ -1702,11 +1702,18 @@ def test_rewrite_rotate_csek_to_cmek(self):
17021702class TestRetentionPolicy (unittest .TestCase ):
17031703 def setUp (self ):
17041704 self .case_buckets_to_delete = []
1705+ self .case_blobs_to_delete = []
17051706
17061707 def tearDown (self ):
1708+ # discard test blobs retention policy settings
1709+ for blob in self .case_blobs_to_delete :
1710+ blob .event_based_hold = False
1711+ blob .temporary_hold = False
1712+ blob .patch ()
1713+
17071714 for bucket_name in self .case_buckets_to_delete :
17081715 bucket = Config .CLIENT .bucket (bucket_name )
1709- retry_429_harder (bucket .delete )()
1716+ retry_429_harder (bucket .delete )(force = True )
17101717
17111718 def test_bucket_w_retention_period (self ):
17121719 import datetime
@@ -1732,6 +1739,8 @@ def test_bucket_w_retention_period(self):
17321739 blob = bucket .blob (blob_name )
17331740 blob .upload_from_string (payload )
17341741
1742+ self .case_blobs_to_delete .append (blob )
1743+
17351744 other = bucket .get_blob (blob_name )
17361745
17371746 self .assertFalse (other .event_based_hold )
@@ -1756,6 +1765,7 @@ def test_bucket_w_retention_period(self):
17561765 self .assertIsNone (other .retention_expiration_time )
17571766
17581767 other .delete ()
1768+ self .case_blobs_to_delete .pop ()
17591769
17601770 def test_bucket_w_default_event_based_hold (self ):
17611771 from google .api_core import exceptions
@@ -1780,6 +1790,8 @@ def test_bucket_w_default_event_based_hold(self):
17801790 blob = bucket .blob (blob_name )
17811791 blob .upload_from_string (payload )
17821792
1793+ self .case_blobs_to_delete .append (blob )
1794+
17831795 other = bucket .get_blob (blob_name )
17841796
17851797 self .assertTrue (other .event_based_hold )
@@ -1791,7 +1803,6 @@ def test_bucket_w_default_event_based_hold(self):
17911803
17921804 other .event_based_hold = False
17931805 other .patch ()
1794-
17951806 other .delete ()
17961807
17971808 bucket .default_event_based_hold = False
@@ -1803,11 +1814,12 @@ def test_bucket_w_default_event_based_hold(self):
18031814 self .assertFalse (bucket .retention_policy_locked )
18041815
18051816 blob .upload_from_string (payload )
1806- self .assertFalse (other .event_based_hold )
1807- self .assertFalse (other .temporary_hold )
1808- self .assertIsNone (other .retention_expiration_time )
1817+ self .assertFalse (blob .event_based_hold )
1818+ self .assertFalse (blob .temporary_hold )
1819+ self .assertIsNone (blob .retention_expiration_time )
18091820
18101821 blob .delete ()
1822+ self .case_blobs_to_delete .pop ()
18111823
18121824 def test_blob_w_temporary_hold (self ):
18131825 from google .api_core import exceptions
@@ -1824,6 +1836,8 @@ def test_blob_w_temporary_hold(self):
18241836 blob = bucket .blob (blob_name )
18251837 blob .upload_from_string (payload )
18261838
1839+ self .case_blobs_to_delete .append (blob )
1840+
18271841 other = bucket .get_blob (blob_name )
18281842 other .temporary_hold = True
18291843 other .patch ()
@@ -1839,6 +1853,7 @@ def test_blob_w_temporary_hold(self):
18391853 other .patch ()
18401854
18411855 other .delete ()
1856+ self .case_blobs_to_delete .pop ()
18421857
18431858 def test_bucket_lock_retention_policy (self ):
18441859 import datetime
0 commit comments