TDD in Python with pytest
- Room:
- Wicklow Hall 2B
- Start (Dublin time):
- Start (your time):
- Duration:
- 180 minutes
Abstract
This workshop will guide you step-by-step through the implementation of a very simple Python library following a strict TDD workflow. At the end of the workshop you will have grasped the main principles of TDD and learned the fundamentals of the Python testing library pytest.
TutorialTesting
Description
Test-Driven Development (TDD) is fortunately one of the names that I can spot most frequently when people talk about methodologies. Unfortunately, many programmers still do not follow it, fearing that it will impose a further burden on the already difficult life of a developer.
TDD is a methodology, something that can help you to create better code. But it is not going to solve all your problems. As with all methodologies you have to pay attention not to commit blindly to it. Try to understand the reasons why certain practices are suggested by the methodology and you will also understand when and why you can or have to be flexible.
During the workshop we will learn what TDD is, and what are the main rules. We will do this developing a very simple Python library together in a sort of a game that mirrors a daily TDD development routine. While we do this, we will also learn how to use pytest, which is one of the most used testing libraries in Python. Oh, we will also learn when NOT to follow the rules!
Setup instructions:
- Create and activate your Python virtual environment
git clone https://github.com/lgiordani/simple_calculator
cd simple_calculator
git checkout --track origin/develop
pip install -r requirements/dev.txt
- You should be able to run
pytest -svv
and get an output like
================================ test session starts ===============================
platform linux -- Python XXXX, pytest-XXXX, py-XXXX, pluggy-XXXX --
cabook/venv3/bin/python3
cachedir: .cache
rootdir: cabook/code/calc, inifile: pytest.ini
plugins: cov-XXXX
collected 0 items
=============================== no tests ran in 0.02s ==============================