Bird
Raised Fist0
PyTesttesting~20 mins

Registering markers in pytest.ini - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
pytest Marker Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of registering markers in pytest.ini
Why is it important to register custom markers in the pytest.ini file when using pytest?
ATo automatically run all tests without specifying any marker
BTo disable all tests that do not have a marker
CTo avoid warnings about unknown markers and enable filtering tests by those markers
DTo change the default test discovery pattern
Attempts:
2 left
💡 Hint
Think about what happens if you use a marker that pytest does not recognize.
❓ Predict Output
intermediate
2:00remaining
Output when using unregistered marker
What warning or error will pytest show when running tests with an unregistered custom marker?
PyTest
[test_sample.py]
import pytest

@pytest.mark.slow
def test_example():
    assert True

# pytest.ini does NOT register 'slow' marker
AWARNING: Unknown pytest.mark.slow - is this a typo? You can register markers in pytest.ini
BERROR: Marker 'slow' not found. Test run aborted.
CNo warnings or errors, test runs normally
DSyntaxError: invalid marker usage
Attempts:
2 left
💡 Hint
Think about pytest's behavior when it sees a marker it does not know.
❓ locator
advanced
1:30remaining
Correct pytest.ini marker registration syntax
Which of the following is the correct way to register a custom marker named database in pytest.ini?
A
[pytest]
markers = database; mark tests that require database access
B
[pytest]
markers = database - mark tests that require database access
C
[pytest]
markers = database # mark tests that require database access
D
[pytest]
markers = database: mark tests that require database access
Attempts:
2 left
💡 Hint
Look for the correct syntax for comments in pytest.ini under markers.
❓ assertion
advanced
2:00remaining
Assertion to check marker registration effect
Given the following pytest.ini and test code, which assertion correctly verifies that the api marker is registered and can be used to select tests?
PyTest
[pytest.ini]
[pytest]
markers = api: mark tests as API tests

[test_api.py]
import pytest

@pytest.mark.api
def test_api_call():
    assert True
Aassert 'api' in pytest.markers
Bassert any(m.startswith('api:') for m in pytest.config.getini('markers'))
Cassert 'api' in pytest.ini
Dassert pytest.mark.api is not None
Attempts:
2 left
💡 Hint
Think about how pytest exposes ini options in code.
❓ framework
expert
2:30remaining
Effect of missing marker registration on test selection
If a custom marker integration is used in tests but NOT registered in pytest.ini, what happens when you run pytest -m integration?
APytest shows a warning about unknown marker but runs tests with the integration marker
BPytest runs all tests ignoring the marker filter
CPytest raises an error and aborts the test run
DPytest runs only tests with the integration marker without warnings
Attempts:
2 left
💡 Hint
Consider how pytest handles unknown markers during test selection.

Practice

(1/5)
1. What is the main purpose of registering markers in the pytest.ini file?
easy
A. To define test data inputs for parameterized tests
B. To organize tests and avoid warnings about unknown markers
C. To automatically generate test reports
D. To speed up test execution by caching results

Solution

  1. Step 1: Understand marker registration purpose

    Markers are labels for tests that help organize and select tests to run.
  2. Step 2: Recognize why registration is needed

    Registering markers in pytest.ini prevents warnings about unknown markers and keeps tests organized.
  3. Final Answer:

    To organize tests and avoid warnings about unknown markers -> Option B
  4. Quick Check:

    Marker registration = organize tests + avoid warnings [OK]
Hint: Markers in pytest.ini prevent warnings and organize tests [OK]
Common Mistakes:
  • Thinking markers speed up tests
  • Confusing markers with test data
  • Assuming markers generate reports
2. Which of the following is the correct way to register a marker named slow in pytest.ini?
easy
A. [markers] slow: marks tests as slow
B. [pytest] markers = slow
C. [pytest] slow = marks tests as slow
D. [markers] slow = marks tests as slow

Solution

  1. Step 1: Identify correct section header

    Markers must be registered under the [markers] section in pytest.ini.
  2. Step 2: Check syntax for marker registration

    The correct syntax uses an equals sign = with a description, e.g., slow = marks tests as slow.
  3. Final Answer:

    [markers] slow = marks tests as slow -> Option D
  4. Quick Check:

    Markers section + equals sign = correct syntax [OK]
Hint: Use [markers] section and '=' to register markers [OK]
Common Mistakes:
  • Using [pytest] instead of [markers]
  • Using colon ':' instead of '='
  • Listing markers without description
3. Given this pytest.ini content:
[markers]
api = marks tests as api tests
slow = marks tests as slow
What happens if you run pytest -m slow?
medium
A. Only tests marked with @pytest.mark.slow will run
B. All tests will run except those marked slow
C. Tests marked with @pytest.mark.api will run
D. Pytest will show a warning about unknown marker

Solution

  1. Step 1: Understand marker filtering with -m option

    The -m option runs tests matching the given marker name.
  2. Step 2: Match marker name with registered markers

    Since slow is registered and used, pytest -m slow runs only tests marked with @pytest.mark.slow.
  3. Final Answer:

    Only tests marked with @pytest.mark.slow will run -> Option A
  4. Quick Check:

    pytest -m marker = runs tests with that marker [OK]
Hint: pytest -m runs tests with the named marker only [OK]
Common Mistakes:
  • Thinking -m excludes tests with the marker
  • Confusing marker names
  • Expecting warnings when marker is registered
4. You added this to your pytest.ini:
[markers]
fast marks tests as fast
But when running tests, pytest shows a warning about unknown marker 'fast'. What is the problem?
medium
A. Marker name 'fast' is reserved and cannot be used
B. Markers section header is misspelled
C. Missing '=' sign between marker name and description
D. pytest.ini file is in the wrong directory

Solution

  1. Step 1: Check marker registration syntax

    The marker line must have an equals sign = between the marker name and its description.
  2. Step 2: Identify missing '=' causing warning

    Here, fast marks tests as fast lacks '=', so pytest treats 'fast' as unknown marker.
  3. Final Answer:

    Missing '=' sign between marker name and description -> Option C
  4. Quick Check:

    Marker line needs '=' sign [OK]
Hint: Always use '=' between marker and description [OK]
Common Mistakes:
  • Forgetting '=' sign
  • Misspelling [markers] header
  • Placing pytest.ini in wrong folder
5. You want to register two markers in pytest.ini: db for database tests and ui for user interface tests. Which pytest.ini content correctly registers both markers?
hard
A. [markers] db = marks tests as database tests ui = marks tests as user interface tests
B. [pytest] markers = db, ui
C. [markers] db: marks database tests ui: marks UI tests
D. [pytest] db = database tests ui = UI tests

Solution

  1. Step 1: Confirm correct section header

    Markers must be under the [markers] section, not [pytest].
  2. Step 2: Verify correct syntax for each marker

    Each marker line uses = with a description, e.g., db = marks tests as database tests.
  3. Step 3: Check all markers are listed separately

    Both db and ui markers are listed on separate lines with descriptions.
  4. Final Answer:

    [markers] db = marks tests as database tests ui = marks tests as user interface tests -> Option A
  5. Quick Check:

    Separate lines under [markers] with '=' for each marker [OK]
Hint: List each marker under [markers] with '=' and description [OK]
Common Mistakes:
  • Using [pytest] instead of [markers]
  • Using commas to list markers
  • Using ':' instead of '='
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