Real Python
  • Start Here
  • Learn Python
    Python Tutorials →
    In-depth articles and video courses
    Learning Paths →
    Guided study plans for accelerated learning
    Quizzes & Exercises →
    Check your learning progress
    Browse Topics →
    Focus on a specific area or skill level
    Community Chat →
    Learn with other Pythonistas
    Office Hours →
    Live Q&A calls with Python experts
    Podcast →
    Hear what’s new in the world of Python
    Books →
    Round out your knowledge and learn offline
    Reference →
    Concise definitions for common Python terms
    Code Mentor →Beta
    Personalized code assistance & learning tools
    Unlock All Content →
  • More
    Learner Stories Python Newsletter Python Job Board Meet the Team Become a Tutorial Writer Become a Video Instructor
  • Search
/
  • Join
  • Sign‑In

— FREE Email Series —

🐍 Python Tricks 💌

Python Tricks Dictionary Merge

🔒 No spam. Unsubscribe any time.

Browse Topics Guided Learning Paths
Basics Intermediate Advanced
ai algorithms api best-practices career community databases data-science data-structures data-viz devops django docker editors flask front-end gamedev gui machine-learning news numpy projects python stdlib testing tools web-dev web-scraping

Table of Contents

  • Testing Your Python Code
  • Getting to Know Python’s unittest
  • Organizing Your Tests With the TestCase Class
    • Creating Test Cases
    • Running unittest Tests
    • Skipping Tests
    • Creating Subtests
  • Exploring the Available Assert Methods
    • Comparing Values
    • Comparing Objects by Their Identity
    • Comparing Collections
    • Running Membership Tests
    • Checking for an Object’s Type
    • Testing for Exceptions
    • Using Custom Assert Methods
  • Using unittest From the Command Line
    • Running Tests
    • Discovering Tests Automatically
    • Using Command-Line Options
  • Grouping Your Tests With the TestSuite Class
    • Creating Test Suites With the TestSuite() Constructor
    • Adding Tests to a Suite: .addTest() and .addTests()
    • Creating Suites With the load_tests() Function
  • Creating Test Fixtures
    • Test Fixtures
    • Class-Level Fixtures
    • Module-Level Fixtures
  • Debugging Failing Tests
    • A Quick Example: FizzBuzz
    • A Test-Driven Example: Rock, Paper, and Scissors
  • Testing With Fake Objects: unittest.mock
  • Conclusion