PyCon UK 2019

How to write readable tests
09-13, 17:00–17:30 (Europe/London), Assembly Room

So often, our tests are much harder to understand than the rest of our code. This is a shame! Find out how to write tests that act as living documentation from which you can gain deeper understanding of your system.


Have you ever found yourself scratching your head when reading an automated test? Even if we take pride in our application code, it’s all too easy for us to neglect readability in our tests.

But tests can be more than just a safety net that nobody reads unless they break. In this talk, I’ll show you how to write Python tests that you will love, and keep coming back to.

Topics will include:

  • Showing what matters and hiding the rest
  • Don’t Repeat Yourself in tests, too
  • Using custom dataclasses
  • Arrange, Act, Assert
  • Telling a story
  • Showing your working
  • Sentinels

Is your proposal suitable for beginners? – no

I like clean application architecture and code that humans can understand. I usually use Python and Django.

I'm the creator of a number of open source Python libraries including Import Linter, which allows you to impose constraints on your project's imports.

I work at Octopus Energy in London, and I like to blog.