0
0
PyTesttesting~10 mins

Running tests (pytest command) - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a simple function test using the pytest command. It verifies that the function returns the expected result.

Test Code - pytest
PyTest
import pytest

def add(a, b):
    return a + b

def test_add():
    assert add(2, 3) == 5
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Test runner starts and discovers test functions in the fileTerminal shows pytest starting and collecting tests-PASS
2pytest runs the test_add functionFunction add(2, 3) is called and returns 5Check if add(2, 3) == 5PASS
3pytest reports test resultTerminal shows one test passedTest passed confirmationPASS
Failure Scenario
Failing Condition: The add function returns a wrong result, e.g., add(2, 3) returns 4
Execution Trace Quiz - 3 Questions
Test your understanding
What does pytest do first when you run the pytest command?
AIt immediately runs all functions
BIt discovers test functions in the file
CIt compiles the code
DIt opens a browser
Key Result
Always verify that your test assertions match the expected output exactly to catch errors early.