-2

Im making a small test with hypothesis, while considering using it more extensively later.

I tried making my test get a param that is integer between 0 and 25. I did the following:

from hypothesis import given
from hypothesis.strategies import integers

@given(x=integers(0, 24))
def test_random(self, x):
    print(x)

but x was always set to 0, so I tried:

@given(x=integers(1, 24))
def test_random(self, x):
    print(x)

and it was always set it to 1 showing that it always taking the min value. what am I doing wrong\where can i configure this to be random?

EDIT: hypothesis version: hypothesis==4.18.3

NotSoShabby
  • 3,316
  • 9
  • 32
  • 56
  • Can you show all of your imports? What version of hypothesis and python are you using? How are you calling the test? – ritlew May 01 '19 at 15:21
  • edited, i run it straight from pycharm – NotSoShabby May 01 '19 at 15:23
  • I get the expected behavior when I copy and paste your code and run it myself. Can you post more context? I see you take the `self` parameter which leads me to believe this is at least a method of a class. – ritlew May 01 '19 at 15:28
  • good catch, the problem is indeed the self object (tested it in an unrelated function adn it worked). the problem is that I have multiple inheritance and a lot going on in my tests classes. how can I debug and know whats causing this? is there anything specific i should look at (maybe overriding something)? – NotSoShabby May 01 '19 at 15:34
  • 1
    I wouldn't be able to make any recommendations without seeing the code for myself – ritlew May 01 '19 at 15:36
  • this seems like inheritance problem with hypothesis. I tried putting the test function in each class I inherit from, and when I got to base (that inherits directly from `unittest.TestCase` ) it worked. starting a new test class that inherits from base and only has that test function, caused the same problem. feels like a bug – NotSoShabby May 01 '19 at 15:44

1 Answers1

0

this seems like inheritance problem with hypothesis. I tried putting the test function in each class I inherit from, and when I got to base (that inherits directly from unittest.TestCase ) it worked. starting a new test class that inherits from base and only has that test function, caused the same problem. feels like a bug

Hypothesis maintainer here - please open an issue with the definition of base, so we can debug this. It definitely should work, and I just tried this on a grand-child subclass of unittest.TestCase without seeing any problems.

Unfortunately we can't help you until you share a reproducing example.

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