This is the website for an older EuroPython. Looking for the latest EuroPython? Click here!
Skip to main content

pytest tips and tricks for a better testsuite

Level:
advanced
Room:
club e
Start:
Duration:
180 minutes

Abstract

pytest lets you write simple tests fast - but also scales to very complex scenarios: Beyond the basics of no-boilerplate test functions, this training will show various intermediate/advanced features, as well as gems and tricks.

To attend this training, you should already be familiar with the pytest basics (e.g. writing test functions, parametrize, or what a fixture is) and want to learn how to take the next step to improve your test suites.

If you're already familiar with things like fixture caching scopes, autouse, or using the built-in tmp_path/monkeypatch/... fixtures: There will probably be some slides about concepts you already know, but there are also various little hidden tricks and gems I'll be showing.

TutorialTesting

Description

We'll cover things like:

  • Recommended pytest settings for more strictness
  • What's xfail and why is it useful?
  • How to mark an entire test file or single parameters
  • Ways to deal with parametrize IDs and syntax
  • Useful built-in pytest fixtures
  • Caching for fixtures
  • Using fixtures implicitly
  • Advanced fixture and parametrization topics
  • How to customize fixtures behavior based on markers or custom CLI arguments
  • Patching, mocking, and alternatives
  • Various useful plugins, and how to write your own
  • Short intro to property-based testing with Hypothesis

The speaker

Florian Bruhin

Florian Bruhin

Florian Bruhin ("The Compiler") is a long-time contributor and maintainer of both the pytest framework and various plugins. In 2013, he started the qutebrowser project, a keyboard-focused web browser based on Python and Qt. In 2015, he discovered pytest - since then, he has given talks and conducted workshops about pytest at various conferences and companies.


← Back to schedule