Skip to content
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

st.functions(..., pure=True) very noisy #3253

Closed
andreareina opened this issue Mar 10, 2022 · 0 comments · Fixed by #3284
Closed

st.functions(..., pure=True) very noisy #3253

andreareina opened this issue Mar 10, 2022 · 0 comments · Fixed by #3284
Assignees
Labels
legibility make errors helpful and Hypothesis grokable

Comments

@andreareina
Copy link

The generated function output its printed at every invocation, when once per distinct input is sufficient with pure functions. Settings can be used to quiet it down but then a lot of desirable output (including h.note()s) is also lost.

minimal example:

import hypothesis as h
import hypothesis.strategies as st

keyfuncs = (
    # choose a return type
    st.sampled_from(
        [
            st.one_of(st.integers(), st.floats(allow_nan=False)),
            st.integers(1, 5).flatmap(
                lambda n: st.tuples(
                    *[st.one_of(st.integers(), st.floats(allow_nan=False))] * n
                )
            ),
        ]
    )
    # get a function with that return type
    .flatmap(lambda strat: st.functions(like=lambda x: x, returns=strat, pure=True))
)


@h.given(f=keyfuncs)
def test_functions_noisy(f):
    h.note(f)
    f(None)
    f(None)
    assert False  # so we get the output

output:

$ pytest hypothesis-functions-noisy.py 
=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.11, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
rootdir: [snip], configfile: pyproject.toml
plugins: anyio-3.3.4, subtests-0.7.0, cov-2.12.1, hypothesis-6.39.3
collected 1 item                                                                                                                                                                                          

hypothesis-functions-noisy.py F

[snip]

----------------------------------------------------------------------------------------------- Hypothesis ------------------------------------------------------------------------------------------------
Falsifying example: test_functions_noisy(
    f=<function hypothesis-functions-noisy.<lambda>.<locals>.<lambda>>,
)
Called function: lambda x: <unknown>(x=None) -> 0
Called function: lambda x: <unknown>(x=None) -> 0
@Zac-HD Zac-HD added the legibility make errors helpful and Hypothesis grokable label Mar 10, 2022
@Zac-HD Zac-HD self-assigned this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legibility make errors helpful and Hypothesis grokable
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants