PyCon UK

Registration Office

TDD in Python with pytest

Discover Test-Driven Development and pytest working on a small project

Leonardo Giordani

Sunday 16th, 14:30 (Room L)
Sunday 16th, 11:30 (Room L)

A workshop (3 hours)


Test-Driven Development is a methodology that can greatly improve the quality of your software. I strongly believe that developing software without following as much as possible a test-driven approach leads to massive delays and greater issues when requirements change (always, that is). In this workshop we will develop a very simple Python project following TDD with the help of the pytest framework. We will work together, and no previous knowledge of testing or the testing framework is required. A minimum knowledge of Python is required, but the project will be very simple, so that we can focus on learning the testing methodology.

The workshop lasts 3 hours.

About Leonardo Giordani

Software Engineer and Open Source Contributor. I am currently working at WeGotPOP, a London-based company that creates software for film casting agencies. We work with Python and Javascript, Docker, AWS, React.

From 2013 I blog some technical thoughts at


  • Introduction to testing and TDD (30 mins)
  • Hands-on development of a simple Python project (2h30): pytest command line, unit tests, how to deal with bugs and new features, exceptions, fixtures, coverage.

Software requirements

You need to have a laptop with Python 3 or Python 2 installed and your editor of choice. You also need to install at least the pytest framework (

On my GitHub account you can find a Cookiecutter package that prepares an empty Python project with pytest and other tools already installed and configured. To use it follow this instructions

python3 -m venv venv3
source venv3/bin/activate
pip install cookiecutter

This will ask some details on the project. Answer with the following values

project_name: pytest_workshop
project_slug: pytest_workshop pypi_username: version: 0.1.0
use_pytest: y
use_pypi_deployment_with_travis: n Select command_line_interface: 2 (no-command-line interface)
create_author_file: y
Select open_source_license: 1 (MIT)

Then go on with

cd pytest_workshop
pip install -r requirements/dev.txt

Once this is done you should be able to run

pytest -svv

and get a nice report that informs you that 1 test is passed.

Please try as much as possible to arrive with a working setup. If you need help you can reach me out on Twitter @tw_lgiordani, I will be at the venue on Sunday morning.

  • The speaker suggested this session is suitable for new programmers.

Back to schedule