Questions tagged [python-hypothesis]

Hypothesis is a Python library for property-based testing; creating unit tests with pseudo-randomly generated data.

Questions about the testing library Hypothesis:

https://hypothesis.readthedocs.io/en/latest/

182 questions
0
votes
2 answers

Same hypothesis test for different django models

I want to use hypothesis to test a tool we've written to create avro schema from Django models. Writing tests for a single model is simple enough using the django extra: from avro.io import AvroTypeException from hypothesis import given from…
kojiro
  • 74,557
  • 19
  • 143
  • 201
0
votes
1 answer

Have a Strategy that does not uniformly choose between different strategies

I'd like to create a strategy C that, 90% of the time chooses strategy A, and 10% of the time chooses strategy B. The random python library does not work even if I seed it since each time the strategy produces values, it generates the same value…
0
votes
1 answer

Using example for strategies that return class instances

I have class A(st.SearchStrategy): def do_draw(self, data): return object_a(b=st.integers(), c=st.boolean()...) class B(st.SearchStrategy): def do_draw(self, data): return object_a(d=st.boolean(), e=st.boolean()...) @given(a=A(),…
0
votes
1 answer

Example test cases for hypothesis based strategies?

What is considered current best practice to test own strategies which are based on hypothesis? There are e.g. tests about how good examples shrink HypothesisWorks/hypothesis-python/tests/quality/test_shrink_quality.py. However I could not find…
thinwybk
  • 4,193
  • 2
  • 40
  • 76
0
votes
1 answer

Hypothesis integer stategy with defined step size between test runs?

I am writing a custom search strategy with builds() (this doesn't matter w.r.t. this question) which shall use hypothesis.strategies.integers(min_value=None, max_value=None) to generate integer data with an explicit step size other than, let's say…
thinwybk
  • 4,193
  • 2
  • 40
  • 76
0
votes
1 answer

How to pass different DataType values in hypothesis and how to check return type and value is correct in Python

Doing sample code for Unit Test in Python with Hypothesis module. Wrote simple getTimeDelta function to get time difference between two dates. Want to write Unit Test of the getTimeDelta function. Used hypothesis modules to get multiple datetime…
Vivek Sable
  • 9,938
  • 3
  • 40
  • 56
0
votes
4 answers

Hypothesis (Python): Omit argument

I have a function like so (it's actually a class, but that's not relevant given Python's duck typing): def myfunc(a=None, b=None): Now I want to write a Hypothesis test which always supplies a, but only sometimes b. I tried from…
Scott Stevens
  • 2,546
  • 1
  • 20
  • 29
0
votes
1 answer

Control individual hypothesis setting on command line (when using pytest)

I have a test suite which uses both pytest and hypothesis. I can specify which hypothesis profile should be used, on the command line, like this pytest --hypothesis-profile some_profile I am struggling to find how to affect a single hypothesis…
jacg
  • 2,040
  • 1
  • 14
  • 27
0
votes
2 answers

Delaying evaluation of Hypothesis strategies for Django models

I have a Django model. Among other things it has a ForeignKey to User: class MyModel(models.Model): foo = models.BooleanField() bar = models.ForeignKey(User) I have a method in my tests that generates me an appropriately shaped User -…
Kristian Glass
  • 37,325
  • 7
  • 45
  • 73
-1
votes
1 answer

How to use @seed in hypothesis?

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…
user5965026
  • 465
  • 5
  • 16
-1
votes
1 answer

Test Python function raising an Error using Hypothesis

Is there a way to use Hypothesis to check if a Python function raises an Error when a particular set of arguments are passed to it? As in, I want the assert to be True if the function fails and not make the test execution stop and the function…
Pratyush Das
  • 460
  • 7
  • 24
-1
votes
1 answer

Referencing one strategy through another

When defining strategies, is it possible to reference another strategy? @given(maximum=strategies.floats(min_value=0), actual=strategies.floats(max_value=maximum)) def foo(maximum, actual): pass This throws NameError: 'maximum' not…
Michael Bianconi
  • 5,072
  • 1
  • 10
  • 25
-1
votes
1 answer

list index out of range when performing database queries in Hypothesis function

I'm using Python Hypothesis to write random tests for database. After 1-2 loops of insert the given values to the table I get list index out of range and @seed to reproduce. There is nothing that suppose to fail, I'm not asserting anything…
-1
votes
1 answer

How to add pyflakes, bottle, hypothesis to a PyCharm project?

How to add testing frameworks and Web frameworks to a PyCharm project. How to add pyflakes, bottle, hypothesis to a PyCharm project? To install, the above mentioned frameworks and any other, follow the below…
Varuna
  • 1,343
  • 3
  • 15
  • 30
-1
votes
1 answer

How to increase or decrease flakiness retry for hypothesis?

Hypothesis tries a test example 3 times if the test example initially fails. eg Flaky: Hypothesis ... produces unreliable results: Falsified on the first call but did not on a subsequent one Is there a way to increase or decrease the number…
1 2 3
12
13