Recall & Review
beginner
What does the pytest marker
-m option do?The
-m option in pytest runs only the tests that have a specific marker. It helps to select tests by tags or categories.Click to reveal answer
beginner
How do you mark a test function with a custom marker in pytest?
Use the
@pytest.mark.marker_name decorator above the test function to assign a marker.Click to reveal answer
beginner
Example: How to run only tests marked as
slow using pytest command line?Run
pytest -m slow to execute only tests marked with @pytest.mark.slow.Click to reveal answer
intermediate
What happens if you run
pytest -m 'not slow'?Pytest runs all tests that do NOT have the
slow marker. The not keyword excludes tests with that marker.Click to reveal answer
intermediate
Why should you register custom markers in
pytest.ini?Registering markers in
pytest.ini avoids warnings and documents the purpose of each marker for better test management.Click to reveal answer
Which pytest command runs only tests marked with
fast?✗ Incorrect
The
-m option filters tests by marker name, so pytest -m fast runs tests marked with @pytest.mark.fast.How do you mark a test as
database in pytest?✗ Incorrect
The correct syntax is
@pytest.mark.database to assign the database marker to a test.What does
pytest -m 'slow or network' do?✗ Incorrect
The
or operator runs tests that have either slow or network markers.Why add markers to
pytest.ini?✗ Incorrect
Registering markers in
pytest.ini prevents warnings about unknown markers and helps document their use.What is the result of
pytest -m 'not network'?✗ Incorrect
The
not operator excludes tests with the network marker, running only tests without it.Explain how to use pytest markers to run a specific group of tests.
Think about tagging tests and selecting them by tag.
You got /3 concepts.
Describe why and how to register custom markers in pytest configuration.
Consider configuration files and team collaboration.
You got /3 concepts.