【问题标题】:How do I replace the choices strategy?如何替换选择策略?
【发布时间】:2021-05-14 13:37:52
【问题描述】:

我更新了 Python 假设,似乎 choices() 现在已被弃用。

文档对data() 和sampled_from() 进行了一些讨论,但不清楚应该如何使用它们来代替choices()。

我的代码看起来像这样:

@precondition(lambda self: not self.flash_light.crossed)
@rule(choice=st.choices)
def make_forward_move(self, choice):
    persons = [x for x in self.persons if not x.crossed]
    pers1 = choice(persons)
    persons.remove(pers1)
    pers2 = choice(persons)

【问题讨论】:

    标签: python python-hypothesis


    【解决方案1】:

    我通过反复试验找到了这个。所需的更改是:

    @rule(data=st.data())
    ...
      ...
       pers1 = data.draw(st.sampled_from(persons))
    

    我的代码的功能仍然存在一些细微的差异,但这些变化足以让它运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 2022-08-20
      • 2016-11-29
      • 2021-06-11
      • 2019-02-17
      • 2023-04-04
      • 2011-04-23
      相关资源
      最近更新 更多