简体   繁体   中英

hypothesis repeats the same values

I'm new to hypothesis and tried this simple code:

@settings(max_examples=5) 
@given(st.integers(), st.integers(), st.integers(), st.integers()) 
def test_foo(a,b,c,d): 
    print(a,b,c,d) 

As you can see, test_foo receives 4 different integers. I run foo 5 times This is the print results:

0 0 0 0
0 0 0 0
-2070532028 -5212 -20927 14943
0 0 0 0
0 0 0 0

4 of the 5 times this test ran, it ran with 4 zeros. This isn't accidental, Every time I run test_foo I get the same results: 3-4 runs with 4 zeros and 1-2 runs with non zeros

How can I get more variant parameters?

The only solution to this issue is to run (many) more than five examples!

Hypothesis doesn't guarantee that it will only produce any particular input once, and in fact we have to produce some duplicates to check for flaky tests. We also prefer to explore a variety of simple examples early on, when it's most efficient. The implementation details of why you see this particular pattern are complicated, so I'll just say that if you run with the default 100 examples it won't be a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM