Articles
Hypothesis is now thread-safe
August 07, 2025
Liam DeVoe

TL;DR: as of version 6.136.9, Hypothesis supports running the same test simultaneously from multiple threads.

Hypothesis has historically had the following thread-safety policy:

  • Running tests in multiple processes: fully supported.
  • Running separate tests in multiple threads: not officially supported, but mostly worked.
  • Running the same test in …
The Hypothesis continuous release process
February 27, 2018
alexwlchan

If you watch the Hypothesis changelog, you'll notice the rate of releases sped up dramatically in 2017. We released over a hundred different versions, sometimes multiple times a day.

This is all thanks to our continuous release process. We've completely automated the process of releasing, so every pull request that …

Smarkets's funding of Hypothesis
January 08, 2018
drmaciver

Happy new year everybody!

In this post I'd like to tell you about one of the nice things that happened in 2017: The Hypothesis work that was funded by Smarkets. Smarkets are an exchange for peer-to-peer trading of bets but, more importantly for us, they are fairly heavy users of …

The Threshold Problem
September 28, 2017
drmaciver

In my last post I mentioned the problem of bug slippage: When you start with one bug, reduce the test case, and end up with another bug.

I've run into another related problem twice now, and it's not one I've seen talked about previously.

The problem is this: Sometimes shrinking …

When multiple bugs attack
September 26, 2017
drmaciver

When Hypothesis finds an example triggering a bug, it tries to shrink the example down to something simpler that triggers it. This is a pretty common feature, and most property-based testing libraries implement something similar (though there are a number of differences between them). Stand-alone test case reducers are also …

Moving Beyond Types
July 16, 2017
drmaciver

If you look at the original property-based testing library, the Haskell version of QuickCheck, tests are very closely tied to types: The way you typically specify a property is by inferring the data that needs to be generated from the types the test function expects for its arguments.

This is …

Solving the Water Jug Problem from Die Hard 3 with TLA+ and Hypothesis
April 05, 2017
nchammas

This post was originally published on the author's personal site. It is reproduced here with his permission.

In the movie Die Hard with a Vengeance (aka Die Hard 3), there is this famous scene where John McClane (Bruce Willis) and Zeus Carver (Samuel L. Jackson) are forced to solve a …

Hypothesis for Computer Science Researchers
March 09, 2017
drmaciver

I'm in the process of trying to turn my work on Hypothesis into a PhD and I realised that I don't have a good self-contained summary as to why researchers should care about it.

So this is that piece. I'll try to give a from scratch introduction to the why …

How Hypothesis Works
December 10, 2016
drmaciver

Hypothesis has a very different underlying implementation to any other property-based testing system. As far as I know, it's an entirely novel design that I invented.

Central to this design is the following feature set which every Hypothesis strategy supports automatically (the only way to break this is by having …

Compositional shrinking
December 08, 2016
drmaciver

In my last article about shrinking, I discussed the problems with basing shrinking on the type of the values to be shrunk.

In writing it though I forgot that there was a halfway house which is also somewhat bad (but significantly less so) that you see in a couple of …

Integrated vs type based shrinking
December 05, 2016
drmaciver

One of the big differences between Hypothesis and Haskell QuickCheck is how shrinking is handled.

Specifically, the way shrinking is handled in Haskell QuickCheck is bad and the way it works in Hypothesis (and also in test.check and EQC) is good. If you're implementing a property based testing system …

3.6.0 Release of Hypothesis for Python
October 31, 2016
drmaciver

This is a release announcement for the 3.6.0 release of Hypothesis for Python. It's a bit of an emergency release.

Hypothesis 3.5.0 inadvertently added a dependency on GPLed code (see below for how this happened) which this release removes. This means that if you are running …

Another invariant to test for encoders
October 17, 2016
drmaciver

The encode/decode invariant is one of the most important properties to know about for testing your code with Hypothesis or other property-based testing systems, because it captures a very common pattern and is very good at finding bugs.

But how do you go beyond it? If encoders are that …

Seeking funding for deeper integration between Hypothesis and pytest
October 01, 2016
drmaciver

Probably the number one complaint I hear from Hypothesis users is that it "doesn't work" with py.test fixtures. This isn't true, but it does have one very specific limitation in how it works that annoys people: It only runs function scoped fixtures once for the entire test, not once …

3.5.0 and 3.5.1 Releases of Hypothesis for Python
September 23, 2016
drmaciver

This is a combined release announcement for two releases. 3.5.0 was released yesterday, and 3.5.1 has been released today after some early bug reports in 3.5.0

Changes

3.5.0 - 2016-09-22

This is a feature release.

  • fractions() and decimals() strategies now support min_value and …
Hypothesis vs. Eris
September 04, 2016
giorgiosironi

Eris is a library for property-based testing of PHP code, inspired by the mature frameworks that other languages provide like QuickCheck, Clojure's test.check and of course Hypothesis.

Here is a side-by-side comparison of some basic and advanced features that have been implemented in both Hypothesis and Eris, which may …

How many times will Hypothesis run my test?
August 31, 2016
drmaciver

This is one of the most common first questions about Hypothesis.

People generally assume that the number of tests run will depend on the specific strategies used, but that's generally not the case. Instead Hypothesis has a fairly fixed set of heuristics to determine how many times to run, which …

Generating recursive data
August 19, 2016
drmaciver

Sometimes you want to generate data which is recursive. That is, in order to draw some data you may need to draw some more data from the same strategy. For example we might want to generate a tree structure, or arbitrary JSON.

Hypothesis has the recursive function in the hypothesis …

How do I use pytest fixtures with Hypothesis?
August 09, 2016
drmaciver

pytest is a great test runner, and is the one Hypothesis itself uses for testing (though Hypothesis works fine with other test runners too).

It has a fairly elaborate fixture system, and people are often unsure how that interacts with Hypothesis. In this article we'll go over the details of …

What is Hypothesis?
July 24, 2016
drmaciver

Hypothesis is a library designed to help you write what are called property-based tests.

The key idea of property based testing is that rather than writing a test that tests just a single scenario, you write tests that describe a range of scenarios and then let the computer explore the …

3.4.2 Release of Hypothesis for Python
July 13, 2016
drmaciver

This is a bug fix release, fixing a number of problems with the settings system:

  • Test functions defined using @given can now be called from other threads (Issue #337)
  • Attempting to delete a settings property would previously have silently done the wrong thing. Now it raises an AttributeError.
  • Creating a …
Hypothesis for Python 3.4.1 Release
July 09, 2016
drmaciver

This is a bug fix release for a single bug:

  • On Windows when running two Hypothesis processes in parallel (e.g. using pytest-xdist) they could race with each other and one would raise an exception due to the non-atomic nature of file renaming on Windows and the fact that you …
Calculating the mean of a list of numbers
July 04, 2016
drmaciver

Consider the following problem:

You have a list of floating point numbers. No nasty tricks - these aren't NaN or Infinity, just normal "simple" floating point numbers.

Now: Calculate the mean (average). Can you do it?

It turns out this is a hard problem. It's hard to get it even close …

Testing as a Complete Specification
June 30, 2016
drmaciver

Sometimes you're lucky enough to have problems where the result is completely specified by a few simple properties.

This doesn't necessarily correspond to them being easy! Many such problems are actually extremely fiddly to implement.

It does mean that they're easy to test though. Lets see how.

Lets look at …

Testing Configuration Parameters
June 13, 2016
drmaciver

A lot of applications end up growing a complex configuration system, with a large number of different knobs and dials you can turn to change behaviour. Some of these are just for performance tuning, some change operational concerns, some have other functions.

Testing these is tricky. As the number of …

Evolving toward property-based testing with Hypothesis
June 05, 2016
jml

Many people are quite comfortable writing ordinary unit tests, but feel a bit confused when they start with property-based testing. This post shows how two ordinary programmers started with normal Python unit tests and nudged them incrementally toward property-based tests, gaining many advantages on the way.

Background

I used to …

Guest Posts Welcome
May 29, 2016
drmaciver

I would like to see more posters on the hypothesis.works blog. I'm particularly interested in experience reports from people who use Hypothesis in the wild. Could that be you?

Details of how to guest post on here:

  1. This site is a Jekyll site on GitHub. To add a post …
Testing Optimizers
May 29, 2016
drmaciver

We've previously looked into testing performance optimizations using Hypothesis, but this article is about something quite different: It's about testing code that is designed to optimize a value. That is, you have some function and you want to find arguments to it that maximize (or minimize) its value.

As well …

Exploring Voting Systems with Hypothesis
May 26, 2016
drmaciver

Hypothesis is, of course, a library for writing tests.

But from an implementation point of view this is hardly noticeable. Really it's a library for constructing and exploring data and using it to prove or disprove hypotheses about it. It then has a small testing library built on top of …

What is Property Based Testing?
May 14, 2016
drmaciver

I get asked this a lot, and I write property based testing tools for a living, so you'd think I have a good answer to this, but historically I haven't. This is my attempt to fix that.

Historically the definition of property based testing has been "The thing that QuickCheck …

Generating the right data
May 11, 2016
drmaciver

One thing that often causes people problems is figuring out how to generate the right data to fit their data model. You can start with just generating strings and integers, but eventually you want to be able to generate objects from your domain model. Hypothesis provides a lot of tools …

You Don't Need Referential Transparency
May 02, 2016
drmaciver

It's a common belief that in order for property based testing to be useful, your code must be referentially transparent. That is, it must be a pure function with no side effects that just takes input data and produces output data and is solely defined by what input data produces …

Testing performance optimizations
April 29, 2016
drmaciver

Once you've flushed out the basic crashing bugs in your code, you're going to want to look for more interesting things to test.

The next easiest thing to test is code where you know what the right answer is for every input.

Obviously in theory you think you know what …

Rule Based Stateful Testing
April 19, 2016
drmaciver

Hypothesis's standard testing mechanisms are very good for testing things that can be considered direct functions of data. But supposed you have some complex stateful system or object that you want to test. How can you do that?

In this article we'll see how to use Hypothesis's rule based state …

QuickCheck in Every Language
April 16, 2016
drmaciver

There are a lot of ports of QuickCheck, the original property based testing library, to a variety of different languages.

Some of them are good. Some of them are very good. Some of them are OK. Many are not.

I thought it would be worth keeping track of which are …

The Purpose of Hypothesis
April 16, 2016
drmaciver

What is Hypothesis for?

From the perspective of a user, the purpose of Hypothesis is to make it easier for you to write better tests.

From my perspective as the primary author, that is of course also a purpose of Hypothesis. I write a lot of code, it needs testing …

Anatomy of a Hypothesis Based Test
April 16, 2016
drmaciver

What happens when you run a test using Hypothesis? This article will help you understand.

The Python version of Hypothesis uses decorators to transform a test function that doesn't use Hypothesis into one that does.

Consider the following example using py.test style testing:

from hypothesis import given
from hypothesis …
The Encode/Decode invariant
April 16, 2016
drmaciver

One of the simplest types of invariant to find once you move past just fuzzing your code is asserting that two different operations should produce the same result, and one of the simplest instances of that is looking for encode/decode pairs. That is, you have some function that takes …

The Economics of Software Correctness
April 15, 2016
drmaciver

You have probably never written a significant piece of correct software.

That's not a value judgement. It's certainly not a criticism of your competence. I can say with almost complete confidence that every non-trivial piece of software I have written contains at least one bug. You might have written small …

Getting started with Hypothesis
April 15, 2016
drmaciver

Hypothesis will speed up your testing process and improve your software quality, but when first starting out people often struggle to figure out exactly how to use it.

Until you're used to thinking in this style of testing, it's not always obvious what the invariants of your code actually are …