← Winnitude! Search  ·  Reader Mode (902 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
REAL PYTHON · Real Python · 42 LINKS

Using Python's assert to Debug and Test Your Code - Real Python

Go to the next lesson

Using Python's assert to Debug and Test Your Code

Darren Jones 12 Lessons 54m intermediate best-practices python

Python's assert statement allows you to write sanity checks in your code. These checks are known as assertions , and you can use them to test if certain assumptions remain true while you're developing your code. If any of your assertions turn false, then you have a bug in your code.

Assertions are a convenient tool for documenting , debugging , and testing code during development. Once you've debugged and tested your code with the help of assertions, then you can turn them off to optimize the code for production. Assertions will help you make your code more efficient, robust, and reliable.

In this video course, you'll learn:

  • What assertions are and when to use them
  • How Python's assert statement works
  • How assert can help you document , debug , and test your code
  • How assertions can be disabled to improve performance in production
  • What common pitfalls you might face when using assert statements

To get the most out of this video course, you should have previous knowledge of expressions and operators , functions , conditional statements , and exceptions . Having a basic understanding of documenting , debugging , and testing Python code is also a plus.

What's Included:

Downloadable Resources:

Start Now

Getting Started With Assertions

5 Lessons 18m

  1. 1. Using Python's assert to Debug and Test Your Code (Overview) 02:09
  2. 2. Getting to Know Assertions 03:50
  3. 3. Understanding assert Statements 06:26
  4. 4. Exploring Common Assertion Formats 03:21
  5. 5. Documenting Your Code With Assertions 02:33

Debugging and Testing Code

4 Lessons 23m

  1. 1. Debugging Your Code With Assertions 04:51
  2. 2. Disabling Assertions in Production 08:40
  3. 3. Setting the PYTHONOPTIMIZE Environment Variable 04:28
  4. 4. Testing Code With Assertions 05:40

Ironing Out Your Assertions

3 Lessons 12m

  1. 1. Understanding Common Pitfalls 07:31
  2. 2. Avoiding More Pitfalls 03:34
  3. 3. Using Python's assert to Debug and Test Your Code (Summary) 01:14
Start Now

About Darren Jones

With 20 years as a teacher of music technology, Darren is keen to bring his skills to the Python table.

» More about Darren

Each tutorial at Real Python is created by a team of developers so that it meets our high quality standards. The team members who worked on this tutorial are:

Aldren

Christopher

Kate

Tappan

Leodanis

Dan

Geir Arne

Martin

Bartosz

Brenda

← Browse All Courses