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
3
votes
2 answers

Strategy for dictionary with optional keys

Currently I am using hypothesis fixed_dictionaries strategy to generate a dictionary with specific keys and data types that are considered valid for my application. I need a strategy which produces this fixed dictionary as well as others with…
Milo
  • 335
  • 4
  • 15
3
votes
2 answers

How can I create configurable custom hypothesis strategies which use `builds()`?

I created custom Hypothesis strategies using builds() and @composite (the design is inspired by this example from the docs). The strategies are designed similar to the pseudo code below: # strategies.py from hypothesis.strategies import builds,…
thinwybk
  • 4,193
  • 2
  • 40
  • 76
3
votes
1 answer

How to write a strategy to generate list of tuples with python hypothesis?

I started using hypothesis to write my tests. I like it, but I am stuck to generate some kind of data. I have a test that use list of data, which can be constructed from tuple(key, value). Key can be text, integer or float, value can be anything…
Jyhess
  • 33
  • 4
3
votes
1 answer

python Hypothesis test with optional parameter

On my project, I am using Hypothesis to test a function. The function under testing accept one mandatory argument called stop and two optional parameters called respectively start and step. If the parameter step is zero, the code under test should…
Michael
  • 2,436
  • 1
  • 36
  • 57
3
votes
1 answer

Using hypothesis and py.test to test compound strategies in python, must I test them one at a time?

I have 3 files, module.py which contains an example function that tests whether an input is numeric. I have a file called test_mymodule_long.py that successfully tests and passes several types of inputs using py.test and hypothesis. I'm using Python…
TSeymour
  • 729
  • 3
  • 17
3
votes
1 answer

How can I use hypothesis, and pytest-tornado yield-based testing, in the same test case?

I'm writing py.test tests of my code that uses the Tornado library. How can I use Hypothesis in my tests that involve coroutines and the IOLoop? I've been able to write yield-based tests without Hypothesis by using pytest-tornado's…
Dan Getz
  • 8,774
  • 6
  • 30
  • 64
3
votes
1 answer

Hypothesis with flatmap not evaluating

I was trying to adapt the documentation's example of integers(min_value=0, max_value=10).flatmap(lambda n: ... lists(lists(integers(), min_size=n, max_size=n))) to generate tuples of 3 integers with 2/3 bounded by another…
automaticgiant
  • 143
  • 1
  • 9
2
votes
1 answer

With `hypothesis`, how to generate two values that satisfy an ordering relation?

When writing tests using hypothesis, from time to time I encounter a situation that I require two distinct values which satisfy a given relation. Think of the start and end of an interval, where start <= end is required. A simple example of what I…
Max Görner
  • 674
  • 7
  • 16
2
votes
1 answer

Pytest: print something in conftest.py without requiring "-s"

I am using environment variables to control some Hypothesis settings in conftest.py: test_max_examples = int(os.environ.get("TEST_MAX_EXAMPLES", "100").strip()) hypothesis.settings.register_profile( "dev", print_blob=True, …
shadowtalker
  • 12,529
  • 3
  • 53
  • 96
2
votes
1 answer

Hypothesis create column with pd.datetime dtype in given test-dataframe

I want to test whether a certain method can handle different dates in a pandas dataframe, which it takes as an argument. The following example should clarify what kind of setup I want. In the example column('Date', dtype=pd.datetime) does not work…
Viktor
  • 583
  • 1
  • 3
  • 10
2
votes
2 answers

Hypothesis library: strategy for the complement of some other strategy

I'm using the Hypothesis library for unit testing. With this library you don't hand-pick inputs, but you define the complete set of inputs for which you want to test. Hypothesis will then sample from this set to look for inputs that break the…
ToonAlfrink
  • 2,501
  • 2
  • 19
  • 19
2
votes
0 answers

How to use pytest, hypothesis and line_profiler / kernprof together?

To figure out Why is this so slow? I wanted to profile my example generation using line_profiler. However, I can't get it to work. Here's what I tried: kernprof -m pytest -n 3 tests/test_conv.py --hypothesis-profile default pytest -m line_profiler…
phdoerfler
  • 470
  • 6
  • 19
2
votes
2 answers

Generate random data for testing a pandas dataframe with hypothesis

I am working a lot of pandas dataframes and I want to test them using pytest and I am using hypothesis to generate the test data. The issues I am having is that it is generating the same data values in each column. I actually don't know how to…
Espoir Murhabazi
  • 5,973
  • 5
  • 42
  • 73
2
votes
1 answer

Creating a multiindex pd.DataFrame using hypothesis library

I need to create a pd.DataFrame with a multiindex. The first index level is a simple range from 1...n. The second level is a datetime index. All columns contain floats. Here's my example for n=2. from datetime import date import pandas as pd from…
Andi
  • 3,196
  • 2
  • 24
  • 44
2
votes
1 answer

Getting 'LazyStrategy' object instead of integer in hypothesis when using flatmap

Working with the python testing framework hypothesis, I would like to achieve a rather complex composition of testing strategies: 1. I would like to test against create strings s which consist of a unique character set. 2. Each of these examples I…
1 2
3
12 13