0
0
PyTesttesting~10 mins

Registering markers in pytest.ini - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that a custom marker slow is registered in pytest.ini and can be used to mark tests. It verifies that pytest recognizes the marker and runs the test accordingly.

Test Code - pytest
PyTest
import pytest

@pytest.mark.slow
def test_example():
    assert 1 + 1 == 2

# pytest.ini content:
# [pytest]
# markers =
#     slow: marks tests as slow to run
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test runner starts pytest and reads pytest.ini configurationpytest.ini file is loaded with 'slow' marker registered-PASS
2pytest discovers test_example function marked with @pytest.mark.slowTest function is found with 'slow' marker attached-PASS
3pytest runs test_exampleTest executes the assertion 1 + 1 == 2Assert that 1 + 1 equals 2PASS
4pytest reports test resultTest passed without errors, marker recognizedTest marked as 'slow' is accepted and runs successfullyPASS
Failure Scenario
Failing Condition: The 'slow' marker is not registered in pytest.ini and pytest raises a warning or error
Execution Trace Quiz - 3 Questions
Test your understanding
What does registering a marker in pytest.ini do?
AIt tells pytest that the marker is valid and avoids warnings
BIt automatically runs tests faster
CIt disables tests with that marker
DIt changes the test function name
Key Result
Always register custom markers in pytest.ini to avoid warnings and clearly document test categories.