Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The condition sys.version_info < (3, 8) correctly skips the test for Python versions less than 3.8.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'windows' instead of 'win32'.
Confusing platform strings for different OS.
✗ Incorrect
sys.platform returns 'win32' on Windows, so the test is skipped when sys.platform == 'win32'.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' which skips versions below 3.10 instead.
Using '==' which only skips exactly 3.10.
✗ Incorrect
To skip on Python 3.10 or higher, the condition should be sys.version_info >= (3, 10).
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' instead of '<' for version check.
Using wrong platform string like 'win32' instead of 'linux'.
✗ Incorrect
sys.version_info < (3, 10) skips Python 3.9 and lower; sys.platform == 'linux' skips Linux platform.
5fill in blank
hardFill 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'
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.
✗ Incorrect
Use '>=' for Python 3.11 or higher, 'win32' for Windows platform, and 'SKIP_TEST' as the environment variable name.