0
0
PyTesttesting~3 mins

Why Running tests by marker (-m) in PyTest? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could run just the tests you need with one simple command?

The Scenario

Imagine you have a big set of tests for your app. You want to run only the tests about login, but you have to open each test file and run them one by one.

The Problem

This manual way is slow and tiring. You might forget some tests or run the wrong ones. It wastes time and can cause mistakes.

The Solution

Using markers with -m lets you tag tests and run just the ones you want with one simple command. It saves time and keeps things organized.

Before vs After
Before
pytest tests/test_login.py
grep 'def test_login' tests/test_login.py | xargs pytest
After
pytest -m login
What It Enables

You can quickly run focused groups of tests anytime, making testing faster and smarter.

Real Life Example

When fixing a bug in the payment system, you run only payment tests marked with @pytest.mark.payment to check your fix without waiting for all tests.

Key Takeaways

Manual test selection is slow and error-prone.

Markers let you tag and run specific test groups easily.

Running tests by marker speeds up your workflow and reduces mistakes.