0
0
PyTesttesting~10 mins

Built-in markers (skip, skipif, xfail) in PyTest - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to skip the test unconditionally.

PyTest
import pytest

@pytest.mark.[1]()
def test_example():
    assert 1 == 1
Drag options to blanks, or click blank then click option'
Askip
Bskipif
Cxfail
Dmark
Attempts:
3 left
💡 Hint
Common Mistakes
Using @pytest.mark.skipif without a condition
Using @pytest.mark.xfail which marks expected failure, not skip
2fill in blank
medium

Complete the code to skip the test only if Python version is less than 3.8.

PyTest
import pytest
import sys

@pytest.mark.[1](sys.version_info < (3, 8))
def test_feature():
    assert True
Drag options to blanks, or click blank then click option'
Askipif
Bskip
Cxfail
Dmark
Attempts:
3 left
💡 Hint
Common Mistakes
Using @pytest.mark.skip without condition
Using @pytest.mark.xfail which marks expected failure
3fill in blank
hard

Fix the error in the code to mark the test as expected to fail.

PyTest
import pytest

@pytest.mark.[1]()
def test_buggy():
    assert 1 == 2
Drag options to blanks, or click blank then click option'
Amark
Bskip
Cskipif
Dxfail
Attempts:
3 left
💡 Hint
Common Mistakes
Using @pytest.mark.skip() which skips the test
Using @pytest.mark.skipif(True) which skips unconditionally
4fill in blank
hard

Fill both blanks to skip the test if the platform is Windows and mark it as expected to fail otherwise.

PyTest
import pytest
import sys

@pytest.mark.[1](sys.platform == 'win32')
@pytest.mark.[2](sys.platform != 'win32')
def test_platform():
    assert False
Drag options to blanks, or click blank then click option'
Askipif
Bskip
Cxfail
Dmark
Attempts:
3 left
💡 Hint
Common Mistakes
Using unconditional skip which can't be conditional
Mixing skip and skipif incorrectly
5fill in blank
hard

Fill the blanks to skip the test if Python version is less than 3.7, xfail if on Linux, and run normally otherwise.

PyTest
import pytest
import sys
import platform

@pytest.mark.[1](sys.version_info < (3, 7))
@pytest.mark.[2](platform.system() == 'Linux')
def test_conditions():
    assert True
Drag options to blanks, or click blank then click option'
Askipif
Bskip
Cxfail
Dmark
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent marker like xfailif
Using skip instead of skipif for version check