What does Flaky: Hypothesis test produces unreliable results mean?

空扰寡人 提交于 2019-12-06 02:12:39

It means more or less what it says: You have a test which failed the first time but succeeded the second time when rerun with the same example. This could be a Hypothesis bug, but it usually isn't. The most common cause of this is that you have a test which depends on some external state - e.g. if you're using a system random number generator rather than a Hypothesis provided one, or if your test creates some files and only fails if the files did not exist at the start of the test. The second most common cause of this is that your failure is a recursion error and the example which triggered it at one level of function calls did not at another.

You haven't really provided enough information to say what's actually happening, so it's hard to provide more specific advice than that. If you're running a recent version of Hypothesis (e.g. 1.9.0 certainly does it) you should have been given quite detailed diagnostics about what is going on - it will tell you what the original exception you got was and it will report if the values passed in seemed to change between calls.

One thing that I haven't seen mentioned a lot, and it might be a relatively new behavior, is that you may want to raise the deadline of your tests. In my experience, if one test case fails due to a missed deadline and the second one passes, you'll see it as a "flaky" test failure.

@hypothesis.settings(deadline=500)

It's been hard for me to find some proper documentation about this behavior that I could personally understand fully, but this seems to fix it for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!