假设似乎不尊重 pytest 的 maxfail 论点
Hypothesis does not seem to honor the maxfail argument of pytest
尽管指定了 maxfail=1
,假设似乎继续生成示例并 运行 它们并在很久以后失败。
有解决办法吗?
这是一个小例子:
from hypothesis.stateful import invariant, rule, RuleBasedStateMachine
class MaxFail(RuleBasedStateMachine):
count = 0
@rule()
def process(self):
self.count += 1
@invariant()
def all_done(self):
print('-- in invariant %d' % self.count)
if self.count > 1:
assert False
MaxFailTest = MaxFail.TestCase
这是因为从 Pytest 的角度来看,整个有状态测试 只是一个测试 - 它调用 MaxFailTest.runTest()
,如果失败它不会 运行 任何其他测试函数。
另一方面,Hypothesis 不知道 those added in its plugin 之外的任何 Pytest 参数或设置。它同样可以与 pytest、unittest 或任何其他测试一起使用 运行ner 因为 它只是包装了您编写的内部测试函数。
简而言之:Hypothesis 不知道 --maxfail
参数,并且 Pytest 不知道测试会失败,直到 Hypothesis 用它找到的最少示例引发错误。
尽管指定了 maxfail=1
,假设似乎继续生成示例并 运行 它们并在很久以后失败。
有解决办法吗?
这是一个小例子:
from hypothesis.stateful import invariant, rule, RuleBasedStateMachine
class MaxFail(RuleBasedStateMachine):
count = 0
@rule()
def process(self):
self.count += 1
@invariant()
def all_done(self):
print('-- in invariant %d' % self.count)
if self.count > 1:
assert False
MaxFailTest = MaxFail.TestCase
这是因为从 Pytest 的角度来看,整个有状态测试 只是一个测试 - 它调用 MaxFailTest.runTest()
,如果失败它不会 运行 任何其他测试函数。
另一方面,Hypothesis 不知道 those added in its plugin 之外的任何 Pytest 参数或设置。它同样可以与 pytest、unittest 或任何其他测试一起使用 运行ner 因为 它只是包装了您编写的内部测试函数。
简而言之:Hypothesis 不知道 --maxfail
参数,并且 Pytest 不知道测试会失败,直到 Hypothesis 用它找到的最少示例引发错误。