@@ -85,7 +85,7 @@ def tmp_commitizen_project(tmp_git_project):
8585 tmp_commitizen_cfg_file = tmp_git_project .join ("pyproject.toml" )
8686 tmp_commitizen_cfg_file .write ('[tool.commitizen]\n version="0.1.0"\n ' )
8787
88- yield tmp_git_project
88+ return tmp_git_project
8989
9090
9191@pytest .fixture
@@ -122,7 +122,7 @@ def _initial(
122122
123123 return tmp_git_project
124124
125- yield _initial
125+ return _initial
126126
127127
128128def _get_gpg_keyid (signer_mail ):
@@ -139,23 +139,31 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project):
139139 # create a temporary GPGHOME to store a temporary keyring.
140140 # Home path must be less than 104 characters
141141 gpg_home = tempfile .TemporaryDirectory (suffix = "_cz" )
142+ old_gnupghome = os .environ .get ("GNUPGHOME" )
142143 if os .name != "nt" :
143144 os .environ ["GNUPGHOME" ] = gpg_home .name # tempdir = temp keyring
144145
145- # create a key (a keyring will be generated within GPUPGHOME)
146- c = cmd .run (
147- f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{ SIGNER } { SIGNER_MAIL } '"
148- )
149- if c .return_code != 0 :
150- raise Exception (f"gpg keygen failed with err: '{ c .err } '" )
151- key_id = _get_gpg_keyid (SIGNER_MAIL )
152- assert key_id
153-
154- # configure git to use gpg signing
155- cmd .run ("git config commit.gpgsign true" )
156- cmd .run (f"git config user.signingkey { key_id } " )
157-
158- yield tmp_commitizen_project
146+ try :
147+ # create a key (a keyring will be generated within GPUPGHOME)
148+ c = cmd .run (
149+ f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{ SIGNER } { SIGNER_MAIL } '"
150+ )
151+ if c .return_code != 0 :
152+ raise Exception (f"gpg keygen failed with err: '{ c .err } '" )
153+ key_id = _get_gpg_keyid (SIGNER_MAIL )
154+ assert key_id
155+
156+ # configure git to use gpg signing
157+ cmd .run ("git config commit.gpgsign true" )
158+ cmd .run (f"git config user.signingkey { key_id } " )
159+
160+ yield tmp_commitizen_project
161+ finally :
162+ if old_gnupghome is not None :
163+ os .environ ["GNUPGHOME" ] = old_gnupghome
164+ elif "GNUPGHOME" in os .environ and os .name != "nt" :
165+ os .environ .pop ("GNUPGHOME" )
166+ gpg_home .cleanup ()
159167
160168
161169@pytest .fixture
0 commit comments