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

Why did Hypothesis give a falsifying example, when manually reproducing with numpy arrays does not fail?

I was trying to write my first ultra-simple numpy testcase, but the first thing I thought of seems to hit a roadblock. So I did this: import numpy as np from hypothesis import given import hypothesis.strategies as hs import hypothesis.extra.numpy as…
pp-mo
  • 468
  • 2
  • 8
0
votes
1 answer

Hypothesis strategy for multiple pandas series/columns with no duplicates

I would like to define a strategy to generate multiple pandas columns which are row-wise unique. For example, the following two columns would be unique, as there are no duplicates of the two columns combined, even though there are duplicates within…
Kosmonaut
  • 128
  • 10
0
votes
1 answer

How do I exit from pdb debugging when running hypothesis?

I like using hypothesis for my unit tests. I also like using pdb for debugging when things go wrong. But trying to use these two together can be very annoying. If I set a breakpoint in a file that is run by hypothesis using pytest -s,…
Ananda
  • 2,925
  • 5
  • 22
  • 45
0
votes
1 answer

Is there a way to specify multiple columns of a dataframe with different strategies in Hypothesis?

I would like to create a dataframe for testing that looks like: target var0 var1 var2 var3 0 0.34 1.43 0.41 0.98 1 -1.43 -0.31 7.43 1.95 I have been able to do this by defining the columns as a dictionary as seen in this answer…
acmshar
  • 153
  • 1
  • 1
  • 7
0
votes
1 answer

How does python-hypothesis shrink a deferred strategy

I am at the moment implementing PBB for Matlab and am somehow influenced by hypothesis. I do not understand how hypothesis handles the shrinking of deferred strategies. In the documentation there is the code snippet import hypothesis.strategies as…
tommsch
  • 582
  • 4
  • 19
0
votes
1 answer

Provide example to hypothesis module and use len-function

the following code causes my test function to fail when running: from hypothesis import given, example import hypothesis.strategies as st import unittest class SomeObject(): def __init__(self, symbol, value): self.__symbol = symbol …
user2606240
  • 641
  • 1
  • 6
  • 20
0
votes
1 answer

Python/Pandas: Unit testing with hypothesis - reproducing falsifying example

Using the hypothesis library for unit testing, I am wondering how I can reproduce a falsifying example pd.DataFrame? The output looks like this: Falsifying example: test_data_frame_data( data= sec_1 sec_2 sec_3 …
Andi
  • 3,196
  • 2
  • 24
  • 44
0
votes
1 answer

Handling assertions/exceptions using python-hypothesis

What is considered to be best practice when it comes to property based testing using the hypothesis library with respect to assertions within the program code? I created a very simple function to show my point. The function simply divides two…
Andi
  • 3,196
  • 2
  • 24
  • 44
0
votes
1 answer

Function for list of tuples/elements in Python Hypothesis

In my unit tests I use the same combination of strategies fairly often: import hypothesis.strategies as st @given(st.text(), st.integers(), st.floats()) def test_stuff(text, integer, float): ... I was hoping I could extract that combination…
Max Power
  • 952
  • 9
  • 24
0
votes
1 answer

How to generate lists of positive floats with a specified size, sum, and a minimum value using Hypothesis

This question is about the Hypothesis library for property-based testing. I want a strategy that would give me lists of positive floats with a fixed size, a specified sum, and such that no elements would be lower than some specified minimum…
Georgy
  • 12,464
  • 7
  • 65
  • 73
0
votes
2 answers

How do I generate a variable sized list from a given list using Hypothesis?

For property-based testing, given a fixed list of values, I need to generate a variable-sized list where order is important and duplicates are allowed. For example, if my fixed list is texts = ['t1', 't2', 't3', 't4'] I would like to generate…
RAbraham
  • 5,956
  • 8
  • 45
  • 80
0
votes
2 answers

hypothesis decorator for inferring all strategies from type hints

The Python module hypothesis has a hypothesis.given decorator, which allows passing hypothesis.infer for individual parameters to derive their strategy from the corresponding type hint. This can be tedious though as all parameters have to be…
Helmut Grohne
  • 6,578
  • 2
  • 31
  • 67
0
votes
1 answer

Can I list which objects are generated by a hypothesis strategy?

hypothesis has a lot of strategies and I'm still struggling with understanding them. It would help me a lot to see which values they generate. Is that possible? MVCE With hypothesis==5.18.3 and pydantic==1.5.1: from typing import Optional from…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
0
votes
1 answer

Is it possible to generate objects from type-annotated classes for testing?

I had a look at hypothesis recently and used it like this: import hypothesis.strategies as s from hypothesis import given @given(s.integers(min_value=-(10 ** 6), max_value=10 ** 6)) def test_factorize(an_integer): if an_integer == 0: #…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
0
votes
1 answer

Hypothesis strategy to generate multiple kwargs

It is natural to write my test in terms of 3 separate numpy arrays, but the first dimension of each numpy array must be of equal length. As a hack, I can simply ask for a larger numpy array @given( arrays=arrays( dtype=float, …
itisme1997
  • 11
  • 1