0
0
PyTesttesting~10 mins

@pytest.mark.skipif with condition - 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 when Python version is less than 3.8.

PyTest
import sys
import pytest

@pytest.mark.skipif(sys.version_info < [1], reason="Python version too low")
def test_example():
    assert True
Drag options to blanks, or click blank then click option'
A(3, 7)
B(3, 8)
C(3, 9)
D(2, 7)
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a tuple for version comparison.
Using the wrong version tuple that does not match the skip condition.
2fill in blank
medium

Complete the code to skip the test if the platform is Windows.

PyTest
import sys
import pytest

@pytest.mark.skipif(sys.platform == [1], reason="Skip on Windows")
def test_platform():
    assert True
Drag options to blanks, or click blank then click option'
A"darwin"
B"linux"
C"win32"
D"cygwin"
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'windows' instead of 'win32'.
Confusing platform strings for different OS.
3fill in blank
hard

Fix the error in the skip condition to correctly skip on Python 3.10 or higher.

PyTest
import sys
import pytest

@pytest.mark.skipif(sys.version_info [1] (3, 10), reason="Skip on Python 3.10+")
def test_version():
    assert True
Drag options to blanks, or click blank then click option'
A>=
B!=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which skips versions below 3.10 instead.
Using '==' which only skips exactly 3.10.
4fill in blank
hard

Fill both blanks to skip the test on Python 3.9 or lower and on Linux platform.

PyTest
import sys
import pytest

@pytest.mark.skipif(sys.version_info [1] (3, 10) or sys.platform == [2], reason="Skip on Python <=3.9 or Linux")
def test_combined():
    assert True
Drag options to blanks, or click blank then click option'
A<
B>=
C"linux"
D"win32"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '<' for version check.
Using wrong platform string like 'win32' instead of 'linux'.
5fill in blank
hard

Fill all three blanks to skip the test on Python 3.11 or higher, on Windows platform, or if an environment variable 'SKIP_TEST' is set to '1'.

PyTest
import sys
import os
import pytest

@pytest.mark.skipif(sys.version_info [1] (3, 11) or sys.platform == [2] or os.getenv([3]) == '1', reason="Skip on Python 3.11+, Windows, or env var")
def test_all_conditions():
    assert True
Drag options to blanks, or click blank then click option'
A>=
B"win32"
C"SKIP_TEST"
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>=' for version check.
Using wrong platform string like 'windows' instead of 'win32'.
Not quoting the environment variable name.