0
0
PyTesttesting~10 mins

Why markers categorize and control tests in PyTest - Test Your Understanding

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

Complete the code to mark the test as slow.

PyTest
import pytest

@pytest.mark.[1]
def test_example():
    assert 1 + 1 == 2
Drag options to blanks, or click blank then click option'
Afast
Bslow
Cskip
Dparametrize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'fast' marker for a slow test.
Confusing 'skip' marker with categorizing tests.
Using 'parametrize' which is for test data, not categorization.
2fill in blank
medium

Complete the code to skip the test when a condition is true.

PyTest
import pytest

@pytest.mark.skipif([1], reason="Not supported")
def test_feature():
    assert True
Drag options to blanks, or click blank then click option'
A1 == 2
BFalse
CTrue
D2 > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using False which does not skip the test.
Using expressions that evaluate to False.
Confusing skipif condition with test assertions.
3fill in blank
hard

Fix the error in the marker usage to run tests with the 'network' marker only.

PyTest
# Run tests with pytest -m [1]
pytest
Drag options to blanks, or click blank then click option'
A'network'
BNetwork
Cnetwork_tests
Dnetwork
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase marker names.
Adding quotes around the marker name.
Using a different marker name than defined.
4fill in blank
hard

Fill both blanks to mark a test to run only on Linux and skip otherwise.

PyTest
import pytest
import sys

@pytest.mark.skipif(sys.platform != [1], reason="Only Linux")
def test_linux_only():
    assert True

# Run with pytest -m [2]
Drag options to blanks, or click blank then click option'
A'linux'
B'win32'
Clinux
Dlinux_only
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted platform names in the condition.
Using wrong platform string like 'win32' for Linux.
Confusing marker name with platform string.
5fill in blank
hard

Fill all three blanks to create a parametrized test with a marker and skip condition.

PyTest
import pytest

@pytest.mark.[1]
@pytest.mark.parametrize("input", [1, 2, 3])
@pytest.mark.skipif(input == [2], reason="Skip input 2")
def test_values(input):
    assert input != 0

# Run tests with pytest -m [3]
Drag options to blanks, or click blank then click option'
Aparam
B2
Attempts:
3 left
💡 Hint
Common Mistakes
Using different marker names in code and command.
Using wrong skip condition value.
Forgetting to quote marker names in code.