Skip to Content
Mastering Object-oriented Python
book

Mastering Object-oriented Python

by Steven F. Lott
April 2014
Beginner to intermediate
634 pages
15h 22m
English
Packt Publishing
Content preview from Mastering Object-oriented Python

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Object-Oriented Python - Second Edition

Mastering Object-Oriented Python - Second Edition

Steven F. Lott

Publisher Resources

ISBN: 9781783280971Supplemental Content