Book Image

Hands-On Test Driven Development with Python [Video]

By : Richard Wells
Book Image

Hands-On Test Driven Development with Python [Video]

By: Richard Wells

Overview of this book

Do you want to be one of the core developers at your company—the person that everyone wants on their team, and who can deliver new features that work on time? Unit Testing and Test-Driven Development (TDD) are key disciplines that can help you achieve that goal. In this video tutorial, you’ll learn about the PyTest testing library and how it’s used to write unit tests in Python. You’ll also set up some common Python development environments to use PyTest. You’ll create isolated test environments with Test Doubles and learn how to implement and use them with unittest.mock. Moving on, you’ll get to know some of the best practices in Unit Testing and TDD and get some hands-on experience with programming by implementing unit tests using TDD in Python. By the end of this course, you’ll be able to apply the practices of Unit Testing and TDD on a daily basis to radically increase the quality of your code and help you and your company achieve your goals faster than ever before. All the code and supporting files for this course are available on Github at https://github.com/PacktPublishing/-Hands-on-Test-Driven-Development-with-Python
Table of Contents (5 chapters)
Chapter 4
Creating an Isolated Test Environment with Test Doubles
Content Locked
Section 5
Adding Code to Checkout Cart to Read Prices from a File
In this video, we will update the Checkout class to have a function to read in item prices from a file and we’ll mock out the file system calls in our unit test. - Implement the 1st test case to be able to call the new readPricesFile method - Implement the second test case where the readPricesFile method is updated to actually open and read the lines from the file - Review the mock setup code in the unit test to ensure you understand how the mocks are allowing the python “with” operator to work and to then iterate over the lines being read from the mocked file object