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
1
vote
1 answer

How to define a strategy in hypothesis to generate a pair of similar recursive objects

I am new to hypothesis and I am looking for a way to generate a pair of similar recursive objects. My strategy for a single object is similar to this example in the hypothesis documentation. I want to test a function which takes a pair of recursive…
stefan
  • 188
  • 1
  • 7
1
vote
2 answers

python-hypothesis: Retrieving or reformatting a falsifying example

Is it possible to retrieve or reformat the falsifying example after a test failure? The point is to show the example data in a different format - data generated by the strategy is easy to work with in the code but not really user friendly, so I'm…
volferine
  • 372
  • 1
  • 9
1
vote
2 answers

hypothesis+unittest tests lock sqlite database

I'm trying to test my Database class. Here is simplified example of it. class Database: """ it has more methods but I show only the most important """ def __init__(self, name): # let's think the db-file exists with tables …
Bogdan
  • 558
  • 2
  • 8
  • 22
1
vote
1 answer

Hypothesis tests: how to sample_from values from another strategy?

I have to test some function with a sample data: data = [ [[10, 20, 30], 10], [[20, 30], 20], [[40], 30], ] where the first element in each row, lists, contains N=(1 to 5) random integer elements generated via: st.lists( …
franchb
  • 1,174
  • 4
  • 19
  • 42
1
vote
1 answer

Generating unique ids that are not repeated in hypothesis

I want to generate unique ids that aren't repeated. I tried to use st.uuids(). This is my code class MyTest() @hypothesis.seed(0) @hypothesis.settings(derandomize=True) …
1
vote
1 answer

Hypothesis search tree

I have a object with many fields. Each field has different range of values. I want to use hypothesis to generate different instances of this object. Is there a limit to the number of combination of field values Hypothesis can handle? Or what does…
1
vote
2 answers

generating conditional data with Hypothesis Python

I want to generate a list of lists of integers of size 2 with the following conditions. the first element should be smaller than the second and all the data should be unique. I could generate each tuple with a custom function but don't know how…
Kevad
  • 2,781
  • 2
  • 18
  • 28
1
vote
1 answer

Can hypothesis be used to generate data of a specific type (ie. zip codes or phone numbers)?

I am looking into using hypothesis for some of my testing. I like that it can generate a large variety of data to find edge cases. However, I'd like to be able to tailor some of my tests just a bit more. For example, I can define a test to generate…
NewGuy
  • 3,273
  • 7
  • 43
  • 61
1
vote
1 answer

Stateful testing gives hypothesis.errors.Flaky: Run failed initially but succeeded on a second try

I am trying to solve a puzzle using Hypothesis similar to what has been done here: http://nchammas.com/writing/how-not-to-die-hard-with-hypothesis Unfortunately it fails intermittently with the Flaky error and I am not able to track down the problem…
sureshvv
  • 4,234
  • 1
  • 26
  • 32
0
votes
0 answers

How to create and compare syrupy snapshots in hypothesis's stateful testing?

I want to create a hypothesis.stateful.RuleBasedStateMachine to run stateful testing in Python. When the test is running, I want it to be deterministic and either update some snapshots or compare with existing, so that I can manually review whether…
0
votes
1 answer

How to use type hint properly for hypothesis's "stateful testing" example?

I'm trying to properly type hint hypothesis's stateful testing example: import shutil import tempfile from collections import defaultdict import hypothesis.strategies as st from hypothesis.database import DirectoryBasedExampleDatabase from…
Jerry
  • 399
  • 1
  • 2
  • 17
0
votes
1 answer

Getting .Flaky: Inconsistent data generation! in Python hypothesis

My test is to create a policy using (API), but API does not allow duplicate rule name. so hypothesis when retries API is bound to give Duplicate name not allowed. If add logic in my code to delete the policy first if same rule name is generated then…
0
votes
1 answer

Strategy to generate a random datetime format

I'd like to define a Hypothesis strategy do generate a random datetime format. Examples of what I'd like it to return: '%Y-%m-%d' '%d/%m/%Y %H:%M:%S' '%m %d %Y %H:%M' '%Y-%W-%a' and so on. Doesn't look like there's anything in hypothesis…
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65
0
votes
1 answer

VSCode creating a .hypothesis/unicode_data/13.0.0/charmap.json.gz file for every project

I'm not sure if it's happening because I installed a new library that has that issue, but now every time I run a new project VSCode creates a ".hypothesis/unicode_data/13.0.0/charmap.json.gz" and it's annoying, how can stop it? I tried looking up…
Kikeshi
  • 3
  • 3
0
votes
1 answer

In the Hypothesis library for Python, why does the text() strategy cause custom strategies to retry?

I have a custom strategy built using composite that draws from text strategy internally. Debugging another error (FailedHealthCheck.data_too_large) I realized that drawing from the text strategy can cause my composite strategy to be invoked roughly…
levand
  • 8,440
  • 3
  • 41
  • 54