Djangocon: Hypothesis, randomised testing for Django - Rae Knowler

Tags: django, djangocon, python

(One of the summaries of a talk at the 2015 Djangocon EU conference).

Rae Knowler talks about hypothesis. It is a property based testing library inspired by Haskell’s Quickcheck. So: it took out a a bunch of good ideas and you don’t need to know a lot of scary Haskell :-)

The core idea is that it uses randomized data. You tell it to test your login page, for instance, with a name, an age and an email address. It then creates 1000 random names/ages/emails and feeds them to your form.

It simplifies examples of failures. What that means: if it finds an error, it tries iterating on it, finding out in the end that perhaps your form doesn’t handle a name with a $ in it. It remembers interesting inputs.

It works with pytest, unittests, everything. It is just a library.

There’s django integration: https://pypi.python.org/pypi/hypothesis-django/ . Custom field types are allowed. It can generate child models. And since last sunday it supports fixtures.

Rae showed a demo. With random numbers, hypothesis reliably found a DivideByZero bug. Nice!

Hypothesis makes discovering this kind of bugs easy. It makes it simple to write tests without having to rigorously figure out the corner cases that break your code.

Holiday picture from the Eifel region. Kronenburg castle, small, in the middle.
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):