Enable B023, PT017: fix loop variable binding and use pytest.raises

This commit is contained in:
Krzysztof kuhy Rudnicki 2025-11-30 15:11:39 +01:00
parent e04983d0b9
commit 8190ca8ab2
3 changed files with 8 additions and 11 deletions

View File

@ -283,8 +283,8 @@ def append_cases_to_unified_test(
if re.search(pattern_no_best, content):
content = re.sub(
pattern_no_best,
lambda m: m.group(0).replace(
m.group(1), f"{base_label}_best_{best_uci}"
lambda m, lbl=base_label, bst=best_uci: m.group(0).replace(
m.group(1), f"{lbl}_best_{bst}"
),
content,
count=1,
@ -293,8 +293,8 @@ def append_cases_to_unified_test(
elif re.search(pattern_with_best, content):
content = re.sub(
pattern_with_best,
lambda m: m.group(0).replace(
m.group(1), f"{base_label}_best_{best_uci}"
lambda m, lbl=base_label, bst=best_uci: m.group(0).replace(
m.group(1), f"{lbl}_best_{bst}"
),
content,
count=1,

View File

@ -10,6 +10,8 @@ import time
import urllib.error
import urllib.request
import pytest
def _req(url, method="GET", data=None):
"""Send an HTTP request and return status code and body."""
@ -92,12 +94,9 @@ def test_crud_roundtrip(tmp_path):
assert code == HTTPStatus.NO_CONTENT
# Ensure gone
try:
with pytest.raises(urllib.error.HTTPError) as exc_info:
_req(base + f"/api/articles/{art_id}")
msg = "Expected 404"
raise AssertionError(msg)
except urllib.error.HTTPError as e:
assert e.code == HTTPStatus.NOT_FOUND
assert exc_info.value.code == HTTPStatus.NOT_FOUND
finally:
srv.terminate()

View File

@ -65,12 +65,10 @@ ignore = [
"S310", # suspicious-url-open - acceptable for scripts
"S110", # try-except-pass - common pattern in scripts
"S112", # try-except-continue - acceptable pattern
"B023", # function-uses-loop-variable - common pattern with closures
"DTZ005", # datetime.now without tz - acceptable for local scripts
"E741", # ambiguous-variable-name - sometimes intentional (e.g. l for list)
"DTZ004", # datetime.utcfromtimestamp - acceptable
"E722", # bare-except - will be fixed where critical
"PT017", # pytest-assert-in-except - acceptable pattern
"PERF401", # manual-list-comprehension - style preference
"RUF005", # collection-literal-concatenation - style preference
"SIM102", # collapsible-if - style preference