简体   繁体   English

假设重复相同的值

[英]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.如您所见, test_foo 接收 4 个不同的整数。 I run foo 5 times This is the print results:我运行 foo 5 次 这是打印结果:

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.此测试运行的 5 次中有 4 次运行了 4 个零。 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这不是偶然的,每次我运行test_foo我都会得到相同的结果:3-4 次运行 4 个零,1-2 次运行非零

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.为什么你会看到这个特定模式的实现细节很复杂,所以我只想说,如果你使用默认的 100 个示例运行它不会有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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