0
0
PyTesttesting~10 mins

Basic assert statement in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the sum of two numbers is correct using a simple assert statement in pytest.

Test Code - pytest
PyTest
def test_sum():
    result = 2 + 3
    assert result == 5, f"Expected 5 but got {result}"
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test function 'test_sum' starts executionPython interpreter ready to run the test-PASS
2Calculate sum of 2 and 3, store in variable 'result'Variable 'result' holds value 5-PASS
3Assert that 'result' equals 5Check if 5 == 5Assert statement verifies result == 5PASS
4Test completes successfullyNo errors raised, test passes-PASS
Failure Scenario
Failing Condition: If the sum calculation is incorrect, e.g., result is not 5
Execution Trace Quiz - 3 Questions
Test your understanding
What does the assert statement check in this test?
AIf the sum of 2 and 3 equals 6
BIf the variable 'result' is defined
CIf the sum of 2 and 3 equals 5
DIf the test function runs without errors
Key Result
Use simple assert statements in pytest to verify expected outcomes clearly and get immediate feedback if something is wrong.