From 561485a85776670bce54d99ae70ba167e658a0f8 Mon Sep 17 00:00:00 2001 From: Joe Esquibel Date: Wed, 23 Sep 2026 15:17:11 -0400 Subject: [PATCH] tests: short IDs for long string parameters (Windows 32,767-char env cap) pytest writes each test's node ID into PYTEST_CURRENT_TEST, and Windows caps one environment variable at 32,767 characters. The ReDoS test in test_commarea_contract.py (#3369) parametrizes on payloads up to 80,013 characters, so it fails during setup on the labelled full-suite Windows jobs (first seen on #3404). A suite-wide pytest_make_parametrize_id hook turns any string parameter longer than 64 characters into its first 40 characters, its length and a short content hash. Co-Authored-By: Claude Opus 5.5 (1M context) --- tests/conftest.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/conftest.py diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..e91ce127f --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,25 @@ +"""Suite-wide pytest hooks. + +Long string parameters get short test IDs. pytest puts every test's node ID in the +PYTEST_CURRENT_TEST environment variable, and Windows caps one environment +variable at 32,767 characters. A ReDoS test that parametrizes on its own +pathological payload (e.g. `"COMMAREA " * 5000`) therefore fails on Windows during +setup with "the environment variable is longer than 32767 characters", before the +test body runs, while Linux and macOS pass. That surfaced first on the labelled +full-suite Windows jobs for #3404, from test_commarea_contract.py (#3369). + +A string longer than _MAX_ID_CHARS becomes its first characters plus a length and +a short content hash. The ID stays readable, stays stable across runs, and stays +distinct for payloads that share a prefix. +""" + +import hashlib + +_MAX_ID_CHARS = 64 + + +def pytest_make_parametrize_id(val): + if isinstance(val, str) and len(val) > _MAX_ID_CHARS: + digest = hashlib.sha256(val.encode("utf-8", "surrogatepass")).hexdigest()[:8] + return f"{val[:40]!r}...len{len(val)}-{digest}" + return None