I Used These Pytest Arguments — My Debugging Time Dropped 70% 📉

Share with friends
⏱️ 𝑹𝒆𝒂𝒅𝒊𝒏𝒈 𝑻𝒊𝒎𝒆: 2 𝘮𝘪𝘯𝘶𝘵𝘦𝘴 ⚡️
Save Story for Later (0)
Please login to bookmark Close

🧪 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

ArgumentDescriptionExampleUse Case
-vVerbose outputpytest -vSee full test names and statuses
-qQuiet modepytest -qMinimal output (just dots or short letters)
-rAShow full reportpytest -rAInclude skipped, xpassed, failed, etc.
-rfReport only failed testspytest -rfQuickly focus on failed cases
-rsReport skipped testspytest -rsFind which tests were skipped
-k "name"Run tests that match stringpytest -k "login"Filter by test name pattern
-k "not api"Exclude matching testspytest -k "not api"Skip certain tests
-m "tag"Run tests with a markerpytest -m "smoke"Run only smoke tests, for example
--maxfail=2Stop after 2 failurespytest --maxfail=2Useful for quick debugging
--tb=shortShort tracebackpytest --tb=shortLess clutter in error logs
--disable-warningsHide warningspytest --disable-warningsClean terminal output
--capture=noShow print statementspytest --capture=noDebug 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:

ScenarioCommandWhy It Helps
Run all tests with names that include “login”pytest -v -k "login"Target specific functionality
Run only smoke testspytest -v -m "smoke"Great for fast validation
Run all tests but stop after 1 failurepytest --maxfail=1 -vSave time in large test suites
Run all tests and hide warningspytest -v --disable-warningsClean up noisy output
Run tests and print debug outputpytest --capture=noSee print() statements in terminal
Show only failed and skipped test summarypytest -v -rs -rfFocus 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 🧪💻

Article Contributors

  • Ishan Dev Shukl
    (Author)
    SDET Manager, Nykaa

    With 13+ years in SDET leadership, I drive quality and innovation through Test Strategies and Automation. I lead Testing Center of Excellence, ensuring high-quality products across Frontend, Backend, and App Testing. "Quality is in the details" defines my approach—creating seamless, impactful user experiences. I embrace challenges, learn from failure, and take risks to drive success.

  • Sasha Hissleton
    (Reviewer)
    Chief Python Officer, QABash

    Serpent by nature, coder by passion! The Python slayer who wraps bugs in loops and scripts solutions with style. Coding is her jungle, and she’s the queen!

Subscribe to QABash Weekly 💥

Dominate – Stay Ahead of 99% Testers!

Leave a Reply

Scroll to Top
×