Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Understanding Test Failures | Handling Exceptions and Failures
Practice
Projects
Quizzes & Challenges
Quizer
Challenges
/
Python Unit Testing Fundamentals

bookUnderstanding Test Failures

Sveip for å vise menyen

When you run tests using Python's unittest framework, it provides detailed output for both passing and failing tests. If a test fails, unittest shows the name of the test, the reason for failure, and the line of code where the failure happened. This output helps you quickly identify what went wrong and where to start debugging.

divide.py

divide.py

test_divide.py

test_divide.py

copy

When a test fails, carefully read the error message to understand the cause. In the sample above, the test test_divide_by_zero failed with a ZeroDivisionError because dividing by zero is not allowed in Python. The failure message shows the exact line where the error happened. To fix the test, you should handle the division by zero case in your code, or adjust the test to expect an exception if that is the intended behavior.

question mark

What should you do when a test fails?

Select all correct answers

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 3. Kapittel 2

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 3. Kapittel 2
some-alt