-1

I'm trying to use @seed here: https://hypothesis.readthedocs.io/en/latest/reproducing.html#reproducing-a-test-run-with-seed

But when I include it before @given, I get the error NameError: name 'seed' is not defined at runtime.

My python script imports hypothesis. Should I be importing something else to get the @seed feature working?

user5965026
  • 465
  • 5
  • 16
  • Could you add your code please? How are you importing `hypothesis`? With `import hypothesis` or `from hypothesis import given`? – D Malan Feb 16 '22 at 20:46
  • @DMalan Sorry, it's a private repository, and I don't think I can share it publicly. Previously, it was just `from hypothesis import given` and I added `import hypothesis` as well, but it didn't solve the "seed is not defined" issue. Note hypothesis testing DOES work when I don't use the `@seed`. – user5965026 Feb 16 '22 at 20:53
  • @DMalan Maybe I'm not using @seed properly? I just added the line `@seed(0)` above the `@given(...)` line. That's supposed to be how it works right? That's what I see on the website – user5965026 Feb 16 '22 at 20:54
  • 1
    @DMalan I figured it out. I need to add `from hypothesis.core import seed` – user5965026 Feb 16 '22 at 20:59

1 Answers1

0

As you note in a comment, you need to from hypothesis import seed before you can use @seed without qualification.

This is not specific to Hypothesis, it's just how imports work in Python generally :-)

Zac Hatfield-Dodds
  • 2,455
  • 6
  • 19