From bc997e4758f3473091cfe6c317c4069324e443b5 Mon Sep 17 00:00:00 2001 From: Jake VanderPlas Date: Wed, 20 Nov 2024 14:06:02 -0800 Subject: [PATCH 1/2] Silence NonInteractiveExampleWarning in test_unary --- array_api_tests/test_special_cases.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/array_api_tests/test_special_cases.py b/array_api_tests/test_special_cases.py index 817805b2..a736f261 100644 --- a/array_api_tests/test_special_cases.py +++ b/array_api_tests/test_special_cases.py @@ -20,11 +20,12 @@ from decimal import ROUND_HALF_EVEN, Decimal from enum import Enum, auto from typing import Any, Callable, Dict, List, Optional, Protocol, Tuple, Literal -from warnings import warn +from warnings import warn, filterwarnings, catch_warnings import pytest from hypothesis import given, note, settings, assume from hypothesis import strategies as st +from hypothesis.errors import NonInteractiveExampleWarning from array_api_tests.typing import Array, DataType @@ -1250,7 +1251,9 @@ def parse_binary_case_block(case_block: str, func_name: str) -> List[BinaryCase] @pytest.mark.parametrize("func_name, func, case", unary_params) def test_unary(func_name, func, case): - in_value = case.cond_from_dtype(xp.float64).example() + with catch_warnings(): + filterwarnings('ignore', category=NonInteractiveExampleWarning) + in_value = case.cond_from_dtype(xp.float64).example() x = xp.asarray(in_value, dtype=xp.float64) out = func(x) out_value = float(out) From 36896431ff01a777d321bdda66b29b419f2f9223 Mon Sep 17 00:00:00 2001 From: Aaron Meurer Date: Wed, 20 Nov 2024 15:35:47 -0700 Subject: [PATCH 2/2] Add comment --- array_api_tests/test_special_cases.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/array_api_tests/test_special_cases.py b/array_api_tests/test_special_cases.py index a736f261..3556e973 100644 --- a/array_api_tests/test_special_cases.py +++ b/array_api_tests/test_special_cases.py @@ -1252,6 +1252,10 @@ def parse_binary_case_block(case_block: str, func_name: str) -> List[BinaryCase] @pytest.mark.parametrize("func_name, func, case", unary_params) def test_unary(func_name, func, case): with catch_warnings(): + # XXX: We are using example here to generate one example draw, but + # hypothesis issues a warning from this. We should consider either + # drawing multiple examples like a normal test, or just hard-coding a + # single example test case without using hypothesis. filterwarnings('ignore', category=NonInteractiveExampleWarning) in_value = case.cond_from_dtype(xp.float64).example() x = xp.asarray(in_value, dtype=xp.float64)