Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Python 3 Object Oriented Programming

You're reading from   Python 3 Object Oriented Programming If you feel it‚Äôs time you learned object-oriented programming techniques, this is the perfect book for you. Clearly written with practical exercises, it‚Äôs the painless way to learn how to harness the power of OOP in Python.

Arrow left icon
Product type Paperback
Published in Jul 2010
Publisher Packt
ISBN-13 9781849511261
Length 404 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Dusty Phillips Dusty Phillips
Author Profile Icon Dusty Phillips
Dusty Phillips
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Python 3 Object Oriented Programming
Credits
About the Author
About the Reviewers
Preface
1. Object-oriented Design FREE CHAPTER 2. Objects in Python 3. When Objects are Alike 4. Expecting the Unexpected 5. When to Use Object-oriented Programming 6. Python Data Structures 7. Python Object-oriented Shortcuts 8. Python Design Patterns I 9. Python Design Patterns II 10. Files and Strings 11. Testing Object-oriented Programs 12. Common Python 3 Libraries Index

Unit testing


Let's start our exploration with Python's built-in test library. This library provides a common interface for unit tests. Unit tests are a special kind of automated test that focuses on testing the least amount of code possible in any one test. Each test tests a single unit of the total amount of available code.

The Python library for this is called, unsurprisingly: unittest. It provides several tools for creating and running unit tests, the most important being the TestCase class. This class provides a set of methods that allow us to compare values, set up tests, and clean up after running them.

When we want to write a set of unit tests for a specific task, we create a subclass of TestCase, and write methods that accept no arguments to do the actual testing. These methods must all start with the string test. If this convention is followed, they'll automatically be run as part of the test process. Normally, the tests set some values on an object and then run a method, and use...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime