0
0
PyTesttesting~5 mins

Running tests by marker (-m) in PyTest - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Apytest -k fast
Bpytest --fast
Cpytest -m fast
Dpytest --marker fast
How do you mark a test as database in pytest?
A@database.mark
B@pytest.database
C@mark.database
D@pytest.mark.database
What does pytest -m 'slow or network' do?
ARuns tests marked with both slow and network
BRuns tests marked with slow or network
CRuns tests without slow or network markers
DRuns all tests except slow and network
Why add markers to pytest.ini?
ATo avoid warnings and document markers
BTo run tests in parallel
CTo disable markers
DTo speed up test execution
What is the result of pytest -m 'not network'?
ARuns tests without the network marker
BRuns only network tests
CRuns all tests
DRuns tests with network and other markers
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.