From 29c5fc7313b2b8f2317e4e6f62f332c3dd702d76 Mon Sep 17 00:00:00 2001 From: Yihang Chen Date: Fri, 16 Oct 2026 11:10:19 -0700 Subject: [PATCH 1/2] Count only the cost warning in coordinate_patch_hooks warn-once test pytest.warns records every warning raised in its block. Since #1907 the coordinate-patch hooks wrap an inner transform annotated with typing.List, and beartype >= 0.22 emits a BeartypeDecorHintPep585DeprecationWarning (a UserWarning subclass) for it under the jaxtyping import hook, so the test saw 5 warnings instead of 1 with an up-to-date beartype. The global filterwarnings ignore does not apply inside pytest.warns. --- .../unit/tools/test_jacobian_lens_coordinate_patch_hooks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py b/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py index b279136f5..a86077d2e 100644 --- a/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py +++ b/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py @@ -41,7 +41,11 @@ def test_coordinate_patch_hooks_warns_once_naming_layer_and_position_counts( ) with pytest.warns(UserWarning, match=r"2 layer\(s\) x 2 position\(s\)") as record: lens.coordinate_patch_hooks(toy_model, 3, 5, layers=[0, 1], positions=[0, 1]) - assert len(record) == 1 + # pytest.warns records every warning raised in the block, including beartype's PEP 585 + # deprecation notices (UserWarning subclasses) that newer beartype releases emit for the + # hooks' typing.List hints under the jaxtyping import hook, so count only the cost warning. + cost_warnings = [w for w in record if "coordinate-patch hooks" in str(w.message)] + assert len(cost_warnings) == 1 def test_coordinate_patch_hooks_rejects_unfitted_layer(toy_model: _ToyBridge) -> None: From b3b89387d0afb85d9bf826c4e4d154b70068c7a0 Mon Sep 17 00:00:00 2001 From: Yihang Chen Date: Sat, 17 Oct 2026 08:33:15 -0700 Subject: [PATCH 2/2] Shorten warn-once test comment --- tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py b/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py index a86077d2e..9a2ce793b 100644 --- a/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py +++ b/tests/unit/tools/test_jacobian_lens_coordinate_patch_hooks.py @@ -41,9 +41,7 @@ def test_coordinate_patch_hooks_warns_once_naming_layer_and_position_counts( ) with pytest.warns(UserWarning, match=r"2 layer\(s\) x 2 position\(s\)") as record: lens.coordinate_patch_hooks(toy_model, 3, 5, layers=[0, 1], positions=[0, 1]) - # pytest.warns records every warning raised in the block, including beartype's PEP 585 - # deprecation notices (UserWarning subclasses) that newer beartype releases emit for the - # hooks' typing.List hints under the jaxtyping import hook, so count only the cost warning. + # Ensure test only fails due to the warning we are testing cost_warnings = [w for w in record if "coordinate-patch hooks" in str(w.message)] assert len(cost_warnings) == 1