File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed
Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 2121import os
2222
2323from google .cloud import storage
24+ import google .api_core .exceptions
2425import pytest
2526
2627import storage_activate_hmac_key
3637STORAGE_CLIENT = storage .Client (project = PROJECT_ID )
3738
3839
39- @pytest .fixture
40+ @pytest .fixture ( scope = "module" )
4041def new_hmac_key ():
4142 """
4243 Fixture to create a new HMAC key, and to guarantee all keys are deleted at
43- the end of each test.
44+ the end of the module.
45+
46+ NOTE: Due to the module scope, test order in this file is significant
4447 """
4548 hmac_key , secret = STORAGE_CLIENT .create_hmac_key (
4649 service_account_email = SERVICE_ACCOUNT_EMAIL , project_id = PROJECT_ID
@@ -100,7 +103,13 @@ def test_deactivate_key(capsys, new_hmac_key):
100103
101104
102105def test_delete_key (capsys , new_hmac_key ):
103- new_hmac_key .state = "INACTIVE"
104- new_hmac_key .update ()
106+ # Due to reuse of the HMAC key for each test function, the previous
107+ # test has deactivated the key already.
108+ try :
109+ new_hmac_key .state = "INACTIVE"
110+ new_hmac_key .update ()
111+ except google .api_core .exceptions .BadRequest :
112+ pass
113+
105114 storage_delete_hmac_key .delete_key (new_hmac_key .access_id , PROJECT_ID )
106115 assert "The key is deleted" in capsys .readouterr ().out
You can’t perform that action at this time.
0 commit comments