PyTest - MarkersWhat is the main purpose of using @pytest.mark.xfail in a test?ATo mark tests that are expected to fail due to known issuesBTo skip tests that are not ready to runCTo mark tests that should always passDTo run tests multiple times automaticallyCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand the purpose of @pytest.mark.xfailThis decorator is used to mark tests that are expected to fail because of known bugs or unfinished features.Step 2: Differentiate from other decoratorsUnlike skipping tests, xfail runs the test but expects failure. It does not mark tests to always pass or run multiple times.Final Answer:To mark tests that are expected to fail due to known issues -> Option AQuick Check:@pytest.mark.xfail = expected failure [OK]Quick Trick: xfail means test expected to fail, not skip or pass [OK]Common Mistakes:MISTAKESConfusing xfail with skipThinking xfail forces test to passAssuming xfail reruns tests
Master "Markers" in PyTest9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepTraceTryChallengeAutomateRecallFrame
More PyTest Quizzes Fixtures - Fixture finalization (request.addfinalizer) - Quiz 11easy Fixtures - @pytest.fixture decorator - Quiz 6medium Parametrize - @pytest.mark.parametrize decorator - Quiz 13medium PyTest Basics and Setup - PyTest installation (pip install pytest) - Quiz 11easy PyTest Basics and Setup - PyTest vs unittest vs nose comparison - Quiz 8hard Test Organization - Test functions - Quiz 12easy Writing Assertions - Basic assert statement - Quiz 8hard Writing Assertions - Why assert is PyTest's core mechanism - Quiz 2easy Writing Assertions - Assert with messages - Quiz 6medium Writing Assertions - Checking membership (in, not in) - Quiz 11easy