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

Collecting sample statistics in the test

I am wondering if there's a way to report statistics of examples in the test using Hypothesis. In other PBTs framework, such as PropEr, provide a way (in this case collect/2) to generate a report of examples in the test. For example, the following…
Yoshi
  • 405
  • 4
  • 12
0
votes
1 answer

Preventing "Interesting" results from python-hypothesis

I am doing some hypothesis testing on async test. My code create and alter databases real-time, and I'm facing a problem with cleanup. Basically, most of the time, I can cleanup the database without a problem. The only time when it get a bit messy…
0
votes
2 answers

How to block the hypothesis pytest plugin

According to the pytest documentation, I can block a plugin using -p no:name. I confirmed that this works for other plugins. However, when I try this with hypothesis it has no effect: (ska3-next) ➜ Chandra.Maneuver git:(master) pytest -v -p…
Tom Aldcroft
  • 2,339
  • 1
  • 14
  • 16
0
votes
1 answer

Generating large examples with the Hypothesis testing package

I am trying to use Hypothesis to stress test some code. I need a large example, but Hypthesis has some built in mechanism to prevent that. For example: from hypothesis import strategies as st st.lists(st.booleans(), min_size=5000).example() I get…
Daniel Mahler
  • 7,653
  • 5
  • 51
  • 90
0
votes
1 answer

Python Hypothesis testing: Is there a way to avoid drawing a LazyStrategy?

If Python hypothesis strategies are too deeply nested, using draw will not create an actual example, but a LazyStrategy. This can be quite problematic at times because the resulting object behaves very differently from an actual example. Is there a…
0
votes
1 answer

Python Hypothesis mixing strategies behavior for DataFrames

The following works as expected from datetime import datetime from hypothesis.extra.pandas import columns, data_frames, indexes import hypothesis.strategies as st def boundarize(d: datetime): return d.replace(minute=15 * (d.minute // 15),…
phaebz
  • 383
  • 5
  • 15
0
votes
1 answer

Parametrized RuleBasedStateMachine

After watching https://www.youtube.com/watch?v=zi0rHwfiX1Q I tried to port the example from C (implementation) and Erlang (testing) to Python and Hypothesis. Given this implementation (the rem function emulates %'s C behavior): import math def…
phaebz
  • 383
  • 5
  • 15
0
votes
1 answer

Simpler way to draw a list of a compound values with requirements of uniqueness and completeness?

Given an object I'm trying to construct: from dataclasses import dataclass @dataclass class Thing: thing_id: str a: int b: float # other attributes For property-based testing I need to generate lists of Thing such that item_id…
Andrea Reina
  • 1,170
  • 8
  • 19
0
votes
2 answers

How to write strategies with arrays that share dimensions in Hypothesis?

I am using hypothesis, specifically the numpy extension, to write tests to upgrade a tensorflow model. This involves generating a number of tensors that share dimensions, such as batch size. For example, what I would like to do: batch_size =…
JMinton
  • 113
  • 1
  • 6
0
votes
1 answer

Generate a Pandas Dataframe with python hypothesis library where one row is dependant on another

I'm trying to use hypothesis to generate pandas dataframes where some column values are dependant on other column values. So far, I haven't been able to 'link' two columns. This code snippet: from hypothesis import strategies as st from…
0
votes
1 answer

Why does hypothesis consider this code slow?

Hypothesis complains vehemently that this was slow: @composite def f_and_g_and_padding(draw, in_channels = channel_ints, out_channels = channel_ints, fs = shapes_2d, fill=None, elements=well_behaved_floats): shape_f = draw(basic_shape) …
phdoerfler
  • 470
  • 6
  • 19
0
votes
1 answer

Disable shrinking in Hypothesis

I have a test for which I would like to disable the shrinking phase. I can do this from hypothesis import given, settings, strategies as st from hypothesis._settings import Phase @settings(report_multiple_bugs=False,…
mac01021
  • 745
  • 4
  • 13
0
votes
1 answer

Make hypothesis test all values

I'm looking for a way to make hypothesis do the following: @given(device=st.test_every_value_of(["cpu", "gpu"]) def test_a_thing(self, device): do_something_with_device(device) But I haven't found a strategy like st.test_every_value_of. What's a…
Richard
  • 56,349
  • 34
  • 180
  • 251
0
votes
1 answer

How to add random integer for each case in Schemathesis?

I'm trying to test an API endpoint with random input for mid and cids (code below). However, whenever I run the test it says missing required positional arguments. Can anyone please help? @schema.parametrize() @schema.given(mid=st.integers(),…
user14862491
  • 1
  • 1
  • 3
0
votes
2 answers

Python hypothesis: How to assert errors in test function

I'm just beginning to use hypothesis for test generation. How can I allow certain errors in the test function when I use hypothesis? Simple example is a division function which works for integers > 0: def divide(a: int, b: int) -> float: return…
Martin Preusse
  • 9,151
  • 12
  • 48
  • 80