From 8190ca8ab2f6594bdcb11ec762ff14199f667834 Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 30 Nov 2025 15:11:39 +0100 Subject: [PATCH] Enable B023, PT017: fix loop variable binding and use pytest.raises --- PYTHON/lichess_bot/tools/generate_blunder_tests.py | 8 ++++---- articles/test_server_api.py | 9 ++++----- pyproject.toml | 2 -- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/PYTHON/lichess_bot/tools/generate_blunder_tests.py b/PYTHON/lichess_bot/tools/generate_blunder_tests.py index 1014679..34350b2 100755 --- a/PYTHON/lichess_bot/tools/generate_blunder_tests.py +++ b/PYTHON/lichess_bot/tools/generate_blunder_tests.py @@ -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, diff --git a/articles/test_server_api.py b/articles/test_server_api.py index ef63331..4b99bc6 100644 --- a/articles/test_server_api.py +++ b/articles/test_server_api.py @@ -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() diff --git a/pyproject.toml b/pyproject.toml index 4af11c1..df6fb1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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