0
0
Selenium Pythontesting~20 mins

Markers for categorization in Selenium Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Marker Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of Markers in pytest
What is the main purpose of using markers in pytest for test categorization?
ATo group tests so you can selectively run subsets based on categories
BTo automatically fix failing tests during runtime
CTo convert test functions into classes
DTo generate HTML reports without additional plugins
Attempts:
2 left
💡 Hint
Think about how you can run only some tests and skip others easily.
Predict Output
intermediate
2:00remaining
Output of pytest marker usage
Given the following pytest code, what will be the output when running `pytest -m smoke`?
Selenium Python
import pytest

@pytest.mark.smoke
def test_login():
    assert True

@pytest.mark.regression
def test_logout():
    assert True

@pytest.mark.smoke
def test_search():
    assert True
ARuns all three tests, all pass
BRuns test_login and test_search only, both pass
CRuns test_logout only, passes
DNo tests run, error about unknown marker
Attempts:
2 left
💡 Hint
The -m option runs tests with the given marker only.
assertion
advanced
2:00remaining
Correct assertion for marker presence
Which assertion correctly checks if a test function has the marker 'regression' in pytest?
Selenium Python
def test_example(request):
    # How to assert 'regression' marker is present on this test?
    pass
Aassert hasattr(request.node, 'regression')
Bassert 'regression' in request.node.keywords
Cassert request.node.marker == 'regression'
Dassert request.node.get_closest_marker('regression') is not None
Attempts:
2 left
💡 Hint
Use the pytest API to get markers safely.
🔧 Debug
advanced
2:00remaining
Fix marker registration error
You get this error when running pytest: "PytestUnknownMarkWarning: Unknown pytest.mark.regression - is this a typo?". What is the cause?
AThe marker 'regression' is not registered in pytest.ini or pyproject.toml
BThe test function name does not start with 'test_'
CThe marker is misspelled in the test code
Dpytest version is too old to support markers
Attempts:
2 left
💡 Hint
Check your pytest configuration files for marker declarations.
framework
expert
2:30remaining
Combining markers and fixtures for selective setup
You want to run a setup fixture only for tests marked with 'db'. Which pytest feature allows this selective fixture application?
AUse pytest hooks to skip fixture for unmarked tests
BUse @pytest.fixture(only_for='db') decorator
CUse autouse=True on fixture and check marker inside fixture code
DUse @pytest.mark.usefixtures('db_setup') on tests and mark tests with 'db'
Attempts:
2 left
💡 Hint
Think about how to run fixture code conditionally without decorating every test.