Bird
Raised Fist0
Selenium Pythontesting~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of using markers in pytest with Selenium tests?
easy
A. To write test cases faster
B. To label and organize tests for selective running
C. To automatically fix test failures
D. To generate test reports

Solution

  1. Step 1: Understand what markers do

    Markers are used to label tests so you can group or select them easily.
  2. Step 2: Identify the main purpose

    This helps run only certain tests or skip some, improving test control.
  3. Final Answer:

    To label and organize tests for selective running -> Option B
  4. Quick Check:

    Markers = Organize tests [OK]
Hint: Markers help pick which tests to run or skip [OK]
Common Mistakes:
  • Thinking markers speed up writing tests
  • Believing markers fix test errors automatically
  • Confusing markers with report generation
2. Which is the correct way to add a marker named smoke to a test function in pytest?
easy
A. @pytest.mark.smoke\ndef test_example(): pass
B. @pytest.mark('smoke')\ndef test_example(): pass
C. @pytest.mark[smoke]\ndef test_example(): pass
D. @pytest.mark->smoke\ndef test_example(): pass

Solution

  1. Step 1: Recall pytest marker syntax

    Markers use dot notation: @pytest.mark.marker_name above the test.
  2. Step 2: Match syntax to options

    Only @pytest.mark.smoke\ndef test_example(): pass uses correct dot notation without extra symbols.
  3. Final Answer:

    @pytest.mark.smoke\ndef test_example(): pass -> Option A
  4. Quick Check:

    Marker syntax = dot notation [OK]
Hint: Use dot notation: @pytest.mark.marker_name [OK]
Common Mistakes:
  • Using parentheses instead of dot notation
  • Using brackets or arrows incorrectly
  • Missing the @ symbol before pytest.mark
3. Given this pytest code snippet, what tests will run if you execute pytest -m smoke?
@pytest.mark.smoke
def test_login(): pass

@pytest.mark.regression
def test_checkout(): pass

def test_search(): pass
medium
A. Only test_login
B. Only test_checkout
C. Both test_login and test_checkout
D. All three tests

Solution

  1. Step 1: Understand pytest -m option

    The -m option runs tests with the given marker only.
  2. Step 2: Identify tests with 'smoke' marker

    Only test_login has @pytest.mark.smoke.
  3. Final Answer:

    Only test_login -> Option A
  4. Quick Check:

    pytest -m smoke runs smoke tests only [OK]
Hint: -m runs tests with matching marker only [OK]
Common Mistakes:
  • Running all tests ignoring markers
  • Confusing marker names
  • Assuming unmarked tests run with any marker
4. You wrote this test with a marker but it does not run when you use pytest -m regression. What is the error?
@pytest.mark.regresion
def test_payment(): pass
medium
A. Test function name is incorrect
B. Missing @ symbol before pytest.mark
C. Marker name is misspelled
D. pytest -m cannot run marked tests

Solution

  1. Step 1: Check marker spelling

    The marker used is 'regresion' but command uses 'regression'.
  2. Step 2: Understand effect of misspelling

    pytest -m regression won't find tests marked 'regresion', so test is skipped.
  3. Final Answer:

    Marker name is misspelled -> Option C
  4. Quick Check:

    Marker spelling must match exactly [OK]
Hint: Check marker spelling matches command exactly [OK]
Common Mistakes:
  • Typos in marker names
  • Forgetting @ before pytest.mark
  • Assuming pytest runs all marked tests without -m
5. You want to run all tests except those marked slow. Which pytest command should you use?
hard
A. pytest -m slow
B. pytest --exclude slow
C. pytest --skip slow
D. pytest -m "not slow"

Solution

  1. Step 1: Understand pytest marker expressions

    To exclude tests with a marker, use -m "not marker_name" syntax.
  2. Step 2: Match command to requirement

    pytest -m "not slow" uses "not slow" to run all tests except those marked slow.
  3. Final Answer:

    pytest -m "not slow" -> Option D
  4. Quick Check:

    Use -m "not marker" to exclude tests [OK]
Hint: Use -m "not marker" to skip marked tests [OK]
Common Mistakes:
  • Using -m marker to run only those tests
  • Using unsupported --skip or --exclude options
  • Not quoting the expression with spaces
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard