Skip to main content
EuroPythonCode of ConductBuy tickets

pytest - simple, rapid and fun testing with Python

Room:
Liffey Hall 2
Start:
08:30 on 12 July 2022
Duration:
180 minutes

Abstract

The pytest tool presents a rapid and simple way to write tests for your Python code. This training gives an introduction with exercises to some distinguishing features. We'll also examine how to run existing non-pytest test suites and discuss migration strategies. Various plugins which extend pytest's functionality even further will be introduced. We'll finish with discussing topics and questions of participants related to their own test suites and usages.

TutorialTesting

Description

The workshop uses Python 3.7 or later, it'd be good if you could set it up before the workshop starts. If you know how, set up a virtualenv with pytest installed - if you don't, that's no problem, I'll cover it at the beginning of the workshop! The material will apply to both pytest 6.2 and 7.x.

This is the planned outline:

  • (30 minutes) pytest feature walkthrough:

    • Automatic test discovery
    • Assertions without boilerplate via the assert statement
    • Configuration and commandline options
    • Marking and skipping tests
    • Data-driven tests via parametrization
    • Exercises / Live demos
  • (60 minutes) pytest fixture mechanism:

    • Setup and teardown via dependency injection
    • Declaring and using function/module/session scoped fixtures
    • Using fixtures from fixture functions
    • Parametrizing fixtures
    • Looking at useful built-in fixtures (managing temporary files, patching, output capturing)
    • Advanced fixture features: Caching, cleanup, implicit fixture use
    • Exercises / Live demos
  • (15 minutes): Running existing unittest suites with pytest:

    • Discussing advantages and limitations
    • Strategies for migrating to pytest
  • (60 minutes): Plugin ecosystem:

    • Examples of available plugins
    • Property-based testing (automated testcase generation) via Hypothesis
    • Overview of useful plugins
    • Writing custom plugins (quick overview)
    • Various live demos
  • (15 minutes): Open space for questions:

    • Leftover questions from the training
    • Other topics depending on interest
    • Buffer if we end up spending more time on something

Basic Python OOP knowledge (e.g. what a class/instance is) is required.

Note that the structure of the workshop is similar to the ones I've given at previous Europythons, but with updated material.


The speaker

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