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

Asserting a value error with property based testing

I have a function which returns the divisors of a number num. The function raises an error if number is negative. I am using the hypothesis library to test this function but I am not sure how I can make it a property-based test. This is my…
user13191962
0
votes
1 answer

Stateful Testing gives up halfway and restarts from the beginning

I am writing a test using Stateful Testing feature of hypothesis. I am finding out that after a certain number of state changes, the testing restarts from the beginning. How can I make it continue along existing path? I have set max_examples=1 and…
sureshvv
  • 4,234
  • 1
  • 26
  • 32
0
votes
1 answer

how to return values from a function that has @given constructor

def fixed_given(self): return @given( test_df=data_frames( columns=columns( ["float_col1"], dtype=float, ), rows=tuples( floats(allow_nan=True,…
0
votes
1 answer

Randomly choose a file inside a folder using Hypothesis

I want to add tests using the Hypothesis library (already use in the software for testing). For these tests, I have to use a set of txt files contained in a folder. I need to randomly choose one of these files each time I run my tests. How to do…
David N
  • 509
  • 4
  • 12
0
votes
1 answer

Can we control test case distribution in Hypothesis Python framework?

Property based framework QuickCheck can be instructed to measure how often a particular test case is generated by using collect and measure utility functions (for example: how often the same person on average places an order, how often empty orders…
Aniket
  • 11
  • 4
0
votes
1 answer

How to create complex data structure with python hypothesis

I'm trying to use hypothesis to generate a text strategy with a complex format. I'm not sure how to build up this kind of data structure. I've tried to build the various elements as composites to then use those as strategies for other composites.…
Mr-Love
  • 50
  • 1
  • 4
0
votes
2 answers

How to start test cases starting from max_value instead of min_value for a Hypothesis strategy?

I'm new to Hypothesis and I want to test a function which takes integer input from Hypothesis Strategy: @given(strategy.integers(min_value=2, max_value=9)) def test_function(t): #... Hypothesis tests the function starting from min_value 2 to 9.…
0
votes
1 answer

How to debug when hypothesis produces flaky test error?

I am using the hypothesis python package for stateful testing. I am getting the following error when I run my tests: hypothesis.errors.Flaky: Unreliable assumption: An example which satisfied assumptions on the first run now fails it. I understand…
Aniket
  • 11
  • 4
0
votes
1 answer

Generate list of dicts with the same keys

I want to generate a list of dicts where all the dicts have the same set of keys. import json import hypothesis from hypothesis import strategies as st @st.composite def list_of_dicts_with_keys_matching(draw,dicts=st.dictionaries(st.text(),…
Hatshepsut
  • 5,962
  • 8
  • 44
  • 80
0
votes
1 answer

Property-based testing and float equality

So I'm trying to compare two implementations of a function with Hypothesis to determine if they work the same way with a huge variety of different inputs that I might not think of myself. I tried using numpy.testing.assert_allclose to compare the…
endolith
  • 25,479
  • 34
  • 128
  • 192
0
votes
1 answer

Hypothesis and empty-ish DataFrames

I'm using Hypothesis to test dataframes, and when they're "empty-ish" I'm getting some unexpected behavior. In the example below, I have a dataframe of all nans, and it's getting viewed as a NoneType object rather than a dataframe (and thus it has…
c74
  • 75
  • 4
0
votes
1 answer

Python property testing with timeout

I have a certain amount of time to test a system. Can I write a Python property test that runs property tests until one hour is up? I looked for a solution in hypothesis but I couldn't find one. I imagine that property-testing libraries have some…
Matthew Piziak
  • 3,430
  • 4
  • 35
  • 49
0
votes
1 answer

Generate valid binary search tree with Python hypothesis by paramertizing recursive calls

How do you parametrize recursive strategies in the Python hypothesis library? I'd like to test that the is_valid_bst function works by generating valid BSTs with a recursive strategy. import hypothesis as hp from hypothesis import strategies as…
Joe
  • 3,370
  • 4
  • 33
  • 56
0
votes
1 answer

Hypothesis strategy: for each "bucket", draw one value from the bucket

I have the following method for generating random data in one of my tests: import random data_categories = { 'a': [1, 2, 3], 'b': [4, 5], 'c': [6, 7, 8] } def make_record(): return [random.choice(vals) for vals in…
shadowtalker
  • 12,529
  • 3
  • 53
  • 96
0
votes
2 answers

How can I generate a boolean expression recursively in Python Hypothesis?

I'm new to Python's Hypothesis library and property based testing in general. I want to generate arbitrarily nested policy expressions with the following grammar: ((A and B) or C) I'm feeling that the recursive strategy is what I want, but I'm…
doughgle
  • 827
  • 1
  • 9
  • 18