0
0
PyTesttesting~10 mins

Test naming conventions in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that a simple function returns the correct result and uses proper test naming conventions in pytest. It verifies that the test function name starts with test_ so pytest can discover and run it.

Test Code - pytest
PyTest
import pytest

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

def test_add_two_numbers():
    result = add(2, 3)
    assert result == 5
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test runner starts and discovers test functions starting with 'test_'pytest collects test_add_two_numbers from the test file-PASS
2pytest runs test_add_two_numbers functionInside test_add_two_numbers, calls add(2, 3)-PASS
3Assert that result equals 5result is 5 from add functionassert result == 5PASS
4Test completes successfullypytest reports test_add_two_numbers PASSED-PASS
Failure Scenario
Failing Condition: Test function is not named starting with 'test_' so pytest does not run it
Execution Trace Quiz - 3 Questions
Test your understanding
Why must pytest test functions start with 'test_'?
ASo pytest can find and run them automatically
BTo make the test run faster
CTo avoid syntax errors
DTo make tests run in parallel
Key Result
Always name your test functions starting with 'test_' in pytest so the test runner can find and execute them automatically.