Skip to main content
EuroPythonCode of ConductLive 📹

Bulletproof Python – Property-Based Testing with Hypothesis

Room:
Wicklow Hall 2A
Start (Dublin time):
Start (your time):
Duration:
180 minutes

Abstract

Property-based testing is a great benefit to the robustness and maintainability of your software. Yet, the technique is still vastly underused in the Python community. The workshop gives a hands-on introduction to Hypothesis and practices different approaches for writing property-based tests.

TutorialTesting

Description

Do you find yourself working through pages of copied and pasted tests to accommodate a simple code change? Does your software frequently break in unexpected ways despite your testing efforts? Don’t despair! Property-based testing could be your way out of that mess. Rather than working harder and writing more test code, property-based testing forces you to work smarter and test more code with fewer tests.

Traditional tests are example-based. They require the developer to come up with arbitrary inputs and check a system’s behavior against explicit outputs. More often than not, developers only think of inputs that are handled correctly by their code, thus leaving bugs hidden. Property-based tests generate the inputs for you and in many cases they’re more likely to find invalid inputs than humans. The difficulty lies in formulating these test cases.

After this workshop you’ll be comfortable with property-based testing using Hypothesis. You’ll have experience requesting appropriate test data from Hypothesis and in writing tests for common and more advanced properties. At work, your co-workers will be impressed by your unbreakable code ;)

Participants are expected to have basic familiarity with unit testing and a testing framework. Provided code examples use pytest.

The workshop material can be found here: https://github.com/seifertm/hypothesis-workshop/tree/europython-2022


The speaker

Michael Seifert

Michael is a consulting software engineer who helps product teams to develop Python software in the cloud. He worked with many different teams from various industries, but none of them practised property-based testing and only few were familiar with the concept.

This prompted him to spread the word about property-based testing and Hypothesis in an effort to help others write more robust and maintainable software.



← Back to schedule