0
0
PyTesttesting~10 mins

Custom markers in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses a custom marker to categorize a test case. It verifies that the test runs only when the marker is used and that the assertion inside the test passes.

Test Code - pytest
PyTest
import pytest

@pytest.mark.slow
def test_addition():
    result = 2 + 3
    assert result == 5
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Pytest starts test collection and identifies test_addition with custom marker 'slow'.Test suite is ready to run tests with markers.-PASS
2Pytest runs test_addition marked with @pytest.mark.slow.Inside test_addition function, calculation 2 + 3 is performed.-PASS
3Assertion checks if result equals 5.Variable result holds value 5.assert result == 5PASS
4Test test_addition completes successfully.Test marked 'slow' passed.-PASS
Failure Scenario
Failing Condition: The assertion fails because the result is not equal to 5.
Execution Trace Quiz - 3 Questions
Test your understanding
What does the custom marker '@pytest.mark.slow' do in this test?
AIt categorizes the test as slow so it can be selectively run.
BIt makes the test run faster.
CIt skips the test automatically.
DIt changes the assertion behavior.
Key Result
Using custom markers helps organize tests by categories like speed or feature, allowing selective test runs and better test management.