Practical testing with pytest
Writing automated tests is often seen as a chore, an optional virtue like flossing your teeth. The truth is, testing is what you need to build an enduring confidence in your abilities as a developer. It illuminates so many other aspects of software development, from requirements to design to acceptance criteria. It will help you deliver software with fewer bugs, and give you the courage to fearlessly refactor.
Sounds great, but how does that help when you are stuck with an existing piece of software and only a handful of tests? Or worse, none? Or worse, some that fail?!
This tutorial will walk you through a small (but real) Python web application and its patchy test set. We’ll practice the skill of reading someone else’s code, examine what test coverage there is and what is missing. We’ll fix a bug or two. We’ll use test driven development to add a new feature. And we’ll even have a go at refactoring.
Along the way, the most useful features of pytest, a Python test runner and library, will be highlighted, showing you how to solve problems like, why does one test failing make the rest fail? How do I test functionality that relies on an external service like a mail server? How do I test that my UI is working? How can I set up the data my application will need to run?
By the end of this tutorial, you’ll have the knowledge to take the most useful features of pytest and apply them to your own work, but more importantly, you’ll know when and why to wield them.
You are comfortable with Python, but either don’t have any experience in testing, or haven’t seen the benefit of testing yet. You don’t need to be a web developer.
Attendees will need:
You’ll need a laptop that you can develop on (with permission to install applications/packages), with a text editor that you like, and git installed. You’ll also need a Github account. A pre-tutorial installation guide will be provided to attendees closer to the date.
About the speaker
Brianna Laugher is a senior software engineer and team lead at Planet Innovation. Her first code review criterion is always “Where are the tests?” She has been a free software enthusiast since way back, or at least 2005. She spoke at PyCon Australia 2012 on "Funcargs and other fun with pytest". She also organises PyLadies Melbourne, and is a past contributor to pytest.