Book Image

Mastering Object-oriented Python

By : Steven F. Lott, Steven F. Lott
Book Image

Mastering Object-oriented Python

By: Steven F. Lott, Steven F. Lott

Overview of this book

Table of Contents (26 chapters)
Mastering Object-oriented Python
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Some Preliminaries
Index

Using setup and teardown


There are three levels of setup and teardown available for the unittest modules. Here are the three different kinds of testing scopes: method, class, and module.

  • Test case setUp() and tearDown() methods: These methods ensure that each individual test method within a TestCase class has had a proper setup and teardown. Often, we'll use the setUp() method to create the unit objects and any mock objects that are required. We don't want to do something costly such as creating whole databases, as these methods are used before and after each test method.

  • Test case setUpClass() and tearDownClass() methods: These methods perform a one-time setup (and teardown) around all the tests in a TestCase class. These methods bracket the sequence of setUp()-testMethod()-tearDown() for each method. This can be a good place to create and destroy the test data or a test schema inside a database.

  • Module setUpModule() and tearDownModule() functions: These standalone functions provide us...