Skip to content

Commit 98438a0

Browse files
committed
test: enable PT022
1 parent 527860c commit 98438a0

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

pyproject.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,7 @@ select = [
235235
"TC005",
236236
"TC006",
237237
]
238-
ignore = [
239-
"E501",
240-
"D1",
241-
"D415",
242-
"PT022", # TODO(bearomorphism): enable this rule
243-
]
238+
ignore = ["E501", "D1", "D415"]
244239
extend-safe-fixes = [
245240
"TC", # Move imports inside/outside TYPE_CHECKING blocks
246241
"UP", # Update syntaxes for current Python version recommendations

tests/conftest.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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]\nversion="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

128128
def _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

Comments
 (0)