0
0
PyTesttesting~10 mins

Why plugins extend PyTest capabilities - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks that a PyTest plugin can extend PyTest by adding a custom marker and that the test using this marker runs and passes correctly.

Test Code - pytest
PyTest
import pytest

# Plugin code to add a custom marker
@pytest.hookimpl(tryfirst=True)
def pytest_configure(config):
    config.addinivalue_line(
        "markers", "custom_marker: mark test to run with custom behavior"
    )

@pytest.mark.custom_marker
def test_example():
    assert 1 + 1 == 2
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1PyTest starts and loads pluginsPyTest environment initialized with custom plugin loaded-PASS
2PyTest discovers test_example marked with @pytest.mark.custom_markerTest file scanned, test_example found with custom_marker-PASS
3PyTest runs test_exampletest_example executingassert 1 + 1 == 2PASS
4PyTest completes test run and reports resultsTest run finished, test_example passedtest_example passed without errorsPASS
Failure Scenario
Failing Condition: The plugin does not register the custom marker, causing PyTest to raise an unknown marker warning or error
Execution Trace Quiz - 3 Questions
Test your understanding
What does the plugin add to PyTest in this test?
AA custom marker named 'custom_marker'
BA new assertion method
CA new test runner
DA new test discovery pattern
Key Result
Plugins extend PyTest by adding features like custom markers, which help organize and control tests. Proper registration of these markers is essential to avoid warnings and ensure tests run as expected.