What if you could run just the tests you want with a simple tag?
Why Custom markers in PyTest? - Purpose & Use Cases
Imagine you have a big set of tests for your app. You want to run only the tests that check login features today, but you have to open each test file and find those tests manually.
This manual way is slow and tiring. You might miss some tests or run the wrong ones. It's easy to make mistakes and waste time running tests you don't need right now.
Custom markers let you tag tests with labels like 'login' or 'slow'. Then you can tell pytest to run only tests with those tags. This saves time and keeps your testing organized.
def test_login_valid(): # test code def test_profile_update(): # test code # Manually run tests by picking them one by one
import pytest @pytest.mark.login def test_login_valid(): # test code @pytest.mark.profile def test_profile_update(): # test code # Run tests with 'login' marker using: pytest -m login
You can quickly run focused groups of tests, making your testing faster and smarter.
A developer fixes a bug in the payment system and runs only tests marked 'payment' to check the fix without waiting for unrelated tests.
Manual test selection is slow and error-prone.
Custom markers tag tests for easy grouping.
Run only needed tests quickly with markers.