0
0
PyTesttesting~10 mins

First PyTest test - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the addition of two numbers works correctly using PyTest. It verifies that 2 + 3 equals 5.

Test Code - PyTest
PyTest
import pytest

def test_addition():
    result = 2 + 3
    assert result == 5
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPyTest test runner is ready to execute tests-PASS
2Calls test_addition functionInside test function, variables initialized-PASS
3Calculates result = 2 + 3result variable holds value 5-PASS
4Checks assertion assert result == 5Comparing result (5) with expected value (5)Assert that result equals 5PASS
5Test ends successfullyTest runner marks test as passed-PASS
Failure Scenario
Failing Condition: If the assertion result == 5 fails (for example, result is not 5)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the assertion in the test check?
AIf result is greater than 5
BIf 2 + 3 equals 6
CIf 2 + 3 equals 5
DIf result is less than 5
Key Result
Always write simple assertions that clearly check expected results. This helps catch errors early and makes tests easy to understand.