EuroPython 2017

TDD in Python with pytest and mock

Speaker(s) Leonardo Giordani

In this tutorial I will start a simple Python project from scratch and will develop it together with the attendees following a strict TDD methodology. The testing framework in use will be pytest, and during the training concepts like coverage, flake8 and mocks (with the official unittest.mock library) will be introduced.

The tutorial is divided in 3 sections:

  • Writing a Python library in TDD
  • Working with mocks and complex tests
  • Refactoring with TDD

During the tutorial we will use Python 3, but the concepts introduced are valid for Python 2 as well.

To setup your laptop follow these steps:

  • Clone the repository: git clone
  • Create a Python virtual environment and install the dependencies: pip install -r requirements.txt

There will be no time to install Python or to set up the repository during the tutorial, so please take your time to configure your laptop. If you need help feel free to ping me during the conference.

in on Thursday 13 July at 14:00 See schedule


  1. Gravatar
    pkg-resources fails to install in my setup, because no present in PyPI for 0.0.0. Using Python 3.6.
    — Ignasi Fosch,
  2. Gravatar
    Hi! Thanks, I fixed it. Now `master` should be fine. I also removed the `mocks` and `refactoring` branches and replaced them with tags.
    — Leonardo Giordani,

New comment