How I Cut Pytest Debugging Time 70% with CLI Arguments
Ishan Dev ShuklAmbassador
Apr 13, 2025

So You’ve Started Writing Tests…
Welcome to the world of Pytest command-line arguments — You’ve just written a handful of tests in Pytest. You run them with pytest… and boom — a wall of output hits your screen. Some dots, some letters, maybe a failure or two, but you’re left wondering…
“Uhh… What just happened?!” 😅
If that sounds familiar, you’re not alone. Pytest is powerful, but its true magic unlocks when you start using it smartly — with command-line flags like -v, -rA, and -k.
Today, I’ll break down exactly what these flags mean, when to use them, and how to combine them to supercharge your test runs like a pro

Why Use Pytest CLI Arguments?
Running tests with just pytest is okay for quick checks. But when your test suite grows, you’ll want to:
✅ Filter specific tests
✅ Get detailed reports
✅ Stop tests after a failure
✅ Categorize and run test groups
✅ Clean up noisy output
Let’s level up!
Pytest Arguments: Quick Reference Table
| Argument | Description | Example | Use Case |
|---|---|---|---|
-v | Verbose output | pytest -v | See full test names and statuses |
-q | Quiet mode | pytest -q | Minimal output (just dots or short letters) |
-rA | Show full report | pytest -rA | Include skipped, xpassed, failed, etc. |
-rf | Report only failed tests | pytest -rf | Quickly focus on failed cases |
-rs | Report skipped tests | pytest -rs | Find which tests were skipped |
-k "name" | Run tests that match string | pytest -k "login" | Filter by test name pattern |
-k "not api" | Exclude matching tests | pytest -k "not api" | Skip certain tests |
-m "tag" | Run tests with a marker | pytest -m "smoke" | Run only smoke tests, for example |
--maxfail=2 | Stop after 2 failures | pytest --maxfail=2 | Useful for quick debugging |
--tb=short | Short traceback | pytest --tb=short | Less clutter in error logs |
--disable-warnings | Hide warnings | pytest --disable-warnings | Clean terminal output |
--capture=no | Show print statements | pytest --capture=no | Debug using print() inside tests |
Sample Use Cases (Real Examples)
Let’s say your file is called test_login.py and it contains:
import pytest
@pytest.mark.smoke
def test_valid_login():
assert "Dashboard" in "Dashboard Page"
@pytest.mark.regression
def test_invalid_login():
assert "Error" in "Login Error Message"
Here’s how you could use CLI options effectively:
| Scenario | Command | Why It Helps |
|---|---|---|
| Run all tests with names that include “login” | pytest -v -k "login" | Target specific functionality |
| Run only smoke tests | pytest -v -m "smoke" | Great for fast validation |
| Run all tests but stop after 1 failure | pytest --maxfail=1 -v | Save time in large test suites |
| Run all tests and hide warnings | pytest -v --disable-warnings | Clean up noisy output |
| Run tests and print debug output | pytest --capture=no | See print() statements in terminal |
| Show only failed and skipped test summary | pytest -v -rs -rf | Focus on what’s broken or skipped |
Pro Tips for Pytest CLI
✅ Combine flags like -v -rA -k "add" for maximum insight
✅ Use -m with markers to categorize and run logical groups of tests
✅ Try --maxfail when you want quick feedback without running the full suite
✅ Use --tb=short to make tracebacks more readable
✅ Add to pytest.ini for default behaviors across the team
Common Pitfalls to Avoid
🚫 Running all tests every time — it’s slow and wasteful
🚫 Ignoring skipped tests — they might contain hidden bugs
🚫 Not using markers — makes filtering test types harder later
🚫 Hardcoding too many custom flags in CI — keep it DRY with config files
Expert Takeaway
Command-line options are more than convenience — they’re critical for productivity and test strategy. Whether you’re debugging locally, running tests in CI/CD pipelines, or managing a growing test suite, mastering Pytest CLI arguments is a game-changer 🧪💻
Was this article helpful?
Ishan Dev ShuklAmbassador
With 14+ years in test automation, Ishan specializes in building scalable automation frameworks, AI-driven testing strategies, and modern quality engineering practices. He writes about automation tools, testing architecture, and the future of QA. His mission is simple: help testers evolve into engineers who build quality into every system.
Join the QABash community
Answer challenges, earn XP, grow your testing career.
Discussion
No comments yet
Be the first to share your thoughts.