Expanded Library

Unit Testing with Python

by Emily Bache

This course will help you to write good unit tests for your Python code, using tools such as unittest, doctest and py.test. Unit tests should improve code quality, and also support future development.

What you'll learn

This course follows on from the Pluralsight "Python Fundamentals" course, and has more detail about unit testing with Python.

In this Python tutorial we will cover libraries and frameworks such as:

  • Unittest
  • Doctest
  • and Py.test

The aim is to help you to write unit tests that improve code quality, and also support future development. Good unit tests should provide immediate value in terms of reduced debugging and better design, and the investment writing them should pay back over the whole lifetime of your software.

Table of contents

Course FAQ

What is unit testing in Python?

Unit testing is when the smallest parts of a software are tested. It is testing that each unit of the software performs the way it is meant to. Python uses the unittest test framework.

What are some benefits of unit testing with Python?

Some benefits include:

  • Improved code quality
  • Support for future development
  • Reduced debugging
  • Better design
  • Reduced costs
  • Provides documentation
What will I learn in this course?

Ultimately you will learn how to write good unit tests for your Python code. Some of topics you will learn include:

  • Python unittest - what it is and how to use it
  • When and why you should write unit tests
  • Using Pytest for unit testing in Python
  • Testable documentation with Doctest
  • Test doubles: Mocks, Fakes, and Stubs
  • Test coverage and parameterized tests
  • Much more
Who should take this course?

This course is for anyone who wants to learn how to test their Python code through unit tests to improve code quality and support future development. Software developers will especially find this course beneficial.

Are there prerequisites to this course?

In order to understand and fully appreciate how to unit test your Python code, you should understand how to write Python code in the first place and have some experience with software development.

About the author

Emily Bache is an independent consultant specializing in automated testing and agile methods. Emily is the author of "The Coding Dojo Handbook: a practical guide to creating a space where good programmers can become great programmers". This book is the result of many years experimenting with the Coding Dojo format for teaching and learning skills around Clean Code, Test Driven Development, Refactoring, and more. Emily spent many years working at AstraZeneca, a multinational pharmaceuticals co... more

Ready to upskill? Get started