Skip to content

Silence NonInteractiveExampleWarning in test_unary #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions array_api_tests/test_special_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -1250,7 +1251,13 @@ 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():
# 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)
out = func(x)
out_value = float(out)
Expand Down
Loading