sureshvv
sureshvv

Reputation: 4422

How do I replace the choices strategy?

I updated Python Hypothesis and it seems that choices() is now deprecated.

Documentation does some handwaving about data() and sampled_from(), but it's not clear how those should be used in place of choices().

My code looks something line this:

@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)

Upvotes: 1

Views: 109

Answers (1)

sureshvv
sureshvv

Reputation: 4422

I was able to find this by trial-and-error. The needed changes are:

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

There are some subtle differences still in how my code functions but these changes were enough to get it to run.

Upvotes: 2

Related Questions