A Talk on Hypothesis

With a couple of goodies from our recent open-source sponsorship

Alexander Schmolck
Smarkets HQ

--

Like many other companies, Smarkets benefits a lot from open-source work. And we try to contribute back: in addition to sending the odd PR to an existing project, releasing our own or hosting hackathons, we also wanted to explore direct financial sponsorship of important open-source development.

One of the many open-source libraries we use and like is David MacIver’s Hypothesis, a property-based testing library for Python.

If you’re not familiar with property-based testing, you might want to have a look at the excellent talk David gave at our London office recently:

(Incidentally, the talk is also well worth watching if you’re not interested in Python or Hypothesis as such.)

We have found property-based testing an invaluable tool for rapidly finding bugs that would have been rather tricky to uncover with handcrafted unit-test examples before they hit production.

However, one downside of property-based tests compared to vanilla unit-tests is that sometimes tests can take very long to run, especially in (C)Python which is hardly renowned for its performance. Worse, the root cause may not always be immediately obvious.

So we commissioned David to work on a few small features that help with this. The first two features are already delivered and part of recent Hypothesis releases:

  1. The deadline feature: treat slow test functions calls (future default 200ms; for now it logs a warning) as failure.
  2. Better ergonomics around random seeds (choice and display; you will now see a message on failure that reads something like this:You can add @seed(67388524433957857561882369659879357765) to this test to reproduce this failure.

Stay tuned for more!

drmaciver.com

--

--